-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdot_split.py
More file actions
55 lines (47 loc) · 1.12 KB
/
Copy pathdot_split.py
File metadata and controls
55 lines (47 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
# I used domain tail(?) such as .com .kr .jp .fr etc
f = open('top-1m.csv')
directory = './dot_list/'
char_set = []
dot = ''
count_dot = 0
put_url = {}
count = 0
os.system('mkdir -p dot_list')
while True:
line = f.readline()
if not line:
break
count = count + 1
line = line.split(',')[1] # removing index
char_set = line.split('.')
dot = char_set[len(char_set)-1]
dot = dot[:-1] # erasing \n
#print char_set
#print dot # .com / .kr / etc
# dictionary ex) .com : www.naver.com
if (dot in put_url.keys()): # .keys() helps to print out all the keys in put_url dict.
for key in put_url:
if (key == dot):
f2 = open(directory + dot,'a+') # append to the files
f2.write(line)
# put_url[dot].append(line[:-1])
f2.close()
else:
put_url[dot] = []
f2 = open(directory + dot,'w')
f2.write(line)
f2.close()
#put_url[dot].append(line[:-1])
if (count % 10000 == 0):
print count
"""
print 'finished ' + put_url
for key,value in put_url: # value is list!
print key,value
f2 = open(directory + key + '.txt', 'w')
for i in range(len(value)):
f2.write(value[i]+'\n')
f2.close()
"""
f.close()