forked from aserg-ufmg/CSIndex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getpid.py
52 lines (40 loc) · 1.07 KB
/
getpid.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 xmltodict
import csv
import urllib2
import sys
def handle_author(_, author):
global pid
if 'hits' in author:
x1 = author['hits']
x2 = x1['hit']
if type(x2) is list:
x3= x2[0]
x3= x3['info']
x4 = x3['url'] + " alias"
else:
x3 = x2['info']
x4 = x3['url']
pid = x4.replace("http://dblp.org/pid/","")
print pid
return True
pid= "null"
return False
f2 = open('out-researchers.csv','w')
reader2 = csv.reader(open(sys.argv[1], 'r'))
count = 1;
pid = "null"
for researcher in reader2:
print str(count) + " >> " + researcher[0]
query = urllib2.quote(researcher[0])
url_dblp = 'http://dblp.org/search/author/api?q=%s' % (query)
bibfile = urllib2.urlopen(url_dblp).read()
xmltodict.parse(bibfile, item_depth=1, item_callback=handle_author)
f2.write(researcher[0])
f2.write(',')
f2.write(researcher[1])
f2.write(',')
f2.write(pid)
f2.write('\n')
count= count + 1;
print "####################################"
f2.close