-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixer.py
52 lines (43 loc) · 1.63 KB
/
mixer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import csv
data_path = "data/lifter-data_social-instagram.csv"
negative_result_path = "results/defunct_accounts"
mixed_path = "results/mixed"
def load_negatives(file: str) -> [] or None:
try:
with open(file) as csvfile:
reader = csv.reader(csvfile)
data = [row[0] for row in reader]
return data
except IOError as error:
print("Error reading dead accounts: {}".format(error))
return None
except BaseException as error:
print("Unknown error: {}".format(error))
return None
def load_data(file: str) -> [] or None:
try:
with open(file, encoding="UTF-8") as csvfile:
reader = csv.reader(csvfile)
data = list(reader)
return data
except IOError as error:
print("Error reading IG accounts: {}".format(error))
return None
except BaseException as error:
print("Unknown error: {}".format(error))
return None
def write_mixed(data: [], negs: []) -> None:
try:
with open(mixed_path, mode="w+", encoding="UTF-8") as mixed_file:
mixed_file.write("{},{}\n".format(data[0][0], data[0][1]))
for elem in data[1:]:
if elem[1] not in negs:
mixed_file.write("{},{}\n".format(elem[0], elem[1]))
except IOError as error:
print("Error with writing mixed file: {}".format(error))
except BaseException as error:
print("Unknown error: {}".format(error))
if __name__ == "__main__":
negatives = load_negatives(negative_result_path)
original_data = load_data(data_path)
write_mixed(original_data, negatives)