forked from emeryberger/CSrankings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean-scholar-links.py
executable file
·56 lines (40 loc) · 1.44 KB
/
clean-scholar-links.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
53
54
55
#!/usr/bin/env python
# CSRankings
# Copyright (C) 2017 by Emery Berger <http://emeryberger.com>
# See COPYING for license information.
# Clean faculty scholar links (sort).
#import google
import os
from collections import *
import time
import codecs
import sys
def csv2dict_str_str(fname):
import csv
with open(fname, mode='r') as infile:
reader = csv.reader(infile)
#for rows in reader:
# print rows[0], "-->", rows[1]
d = { rows[0].strip(): rows[1].strip() for rows in reader}
return d
scholarLinks1 = csv2dict_str_str('scholar.csv')
# Sort
scholarLinks = OrderedDict(sorted(scholarLinks1.items(), key=lambda t: t[0]))
with codecs.open("scholar2.csv", "w", "utf8") as outfile:
outfile.write("name,scholarid\n")
for name in scholarLinks:
if (name == "name"):
continue
outfile.write(name.decode('utf8') + "," + scholarLinks[name] + "\n")
outfile.flush()
os.rename("scholar2.csv","scholar.csv")
checked1 = csv2dict_str_str('scholar-visited.csv')
# Sort
checked = OrderedDict(sorted(checked1.items(), key=lambda t: t[0]))
now = time.time()
os.rename('scholar-visited.csv','scholar-visited-'+str(now)+'.csv')
with codecs.open("scholar-visited.csv", "w", "utf8") as visitedFile:
visitedFile.write('name,date\n')
for name in checked:
visitedFile.write(name.decode('utf8') + "," + str(checked[name]) + "\n")
os.remove('scholar-visited-'+str(now)+'.csv')