-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_departments.py
More file actions
39 lines (33 loc) · 1.12 KB
/
parse_departments.py
File metadata and controls
39 lines (33 loc) · 1.12 KB
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
import io
import pickle
# Read throrugh text file line by line
# Each line has the ID number of the sender, separated by a space from the number ID of the receiver
def parse_emails(filename):
with open(filename) as fp:
line = fp.readline()
departments = {}
cnt = 1
while line:
if cnt % 1000 == 0:
print(cnt)
line = fp.readline()
cnt += 1
data = line.split()
if len(data) < 2:
break
person = data[0]
dept = data[1]
departments[person] = dept
return departments
if __name__ == '__main__':
departments = parse_emails('./email-Eu-core-department-labels.txt')
print(departments['3'])
# Pickle the copurchases dictionary to save the data and run faster later
file_Name = "email-departments-12-05"
# open the file for writing
picklefile = open(file_Name,'wb')
# this writes the object a to the
pickle.dump(departments, picklefile)
# here we close the fileObject
picklefile.close()
print("Done")