-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofileLinker.py
More file actions
48 lines (37 loc) · 1.02 KB
/
Copy pathprofileLinker.py
File metadata and controls
48 lines (37 loc) · 1.02 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
import cPickle as pickle
import json
import glob
from bs4 import BeautifulSoup as bs
import codecs
import pdb
f1 = codecs.open('data/profilematches.txt', 'w', 'utf-8')
f2 = codecs.open('data/notfound.txt', 'w', 'utf-8')
files = glob.glob('data/profilepages/*.html')
needed = []
for file in files:
needed.append(file.split('/')[2][:-5])
# for uid in needed:
# with open('data/profilepages/'+uid+'.html', 'r') as f1:
# soup = bs(f1.read(), 'html.parser')
users = pickle.load(open('allusersinfo.p', 'rb'))
with open('data/ProfileData 4.json', 'r') as f3:
x = json.loads(f3.read())
umap = {}
for y in x:
if y['name']:
umap[y['name']] = y
#pdb.set_trace()
print len(umap)
print len(needed)
for uid in needed:
with open('data/profilepages/'+uid+'.html', 'r') as f3:
soup = bs(f3.read(), 'html.parser')
try:
name = soup.find(id='name').text
except:
f2.write(uid+','+users[uid]['name']+',signup?\n')
continue
if name in umap:
f1.write(uid+','+name+'\n')
else:
f2.write(uid+','+users[uid]['name']+','+name+'\n')