-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
34 lines (27 loc) · 1.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
zapros = input("запрос (слово-часть ссылки) (ex: vk.)")
count = 0
try:
inputFile = open(input("входной файл: "), "r+", encoding="utf-8")
with open("tmp.txt", "w+", encoding="utf-8") as tmpFile:
for line in inputFile:
line = line.replace("http://","").replace("https://","")
if line.count(zapros) != 0:
split = line.split(":")
if len(split) < 3:
print("ошибка формата - "+ line)
continue
tmpFile.write(split[1]+":"+split[2]+"\r\n")
with open(zapros + ".txt", "w+", encoding="utf-8") as OutFile:
lines = list(set(open("tmp.txt", "r+",encoding="utf-8").readlines()))
for line in lines:
if len(line) < 2 and line.count(":") != 2:
continue
count += 1
OutFile.write(line)
except Exception as ex:
print(ex)
print(f"Закончил! Всего {count} Выходной файл - " +zapros+".txt")
os.remove("tmp.txt")
input()
input()