forked from krzywon/saspubs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JIF.py
78 lines (70 loc) · 2.27 KB
/
JIF.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import json
import csv
DEBUG = False
CSV_SOURCE_FILE = "JournalHomeGrid.csv"
SKIP_LINES = 1
EXPORT_KEYS = [
"Journal Impact Factor"
]
def make_lookup():
cf = open(CSV_SOURCE_FILE, "r")
for i in range(SKIP_LINES):
cf.readline()
reader = csv.DictReader(cf)
lookup = {}
for row in reader:
issn = row["ISSN"]
lookup[issn] = row
return lookup
def make_lookup_bytitle():
cf = open(CSV_SOURCE_FILE, "r")
for i in range(SKIP_LINES):
cf.readline()
reader = csv.DictReader(cf)
lookup = {}
for row in reader:
title = row["Full Journal Title"].upper()
lookup[title] = row
return lookup
def update_JIF(values):
lookup = make_lookup()
for v in values:
if "ISSN" in v:
for issn in v["ISSN"]:
if issn in lookup:
for k in EXPORT_KEYS:
v[k] = float(lookup[issn][k])
continue
def update_JIF_bytitle(values):
lookup = make_lookup_bytitle()
for v in values:
if "container-title" in v:
title = v["container-title"].upper()
if title in lookup:
for k in EXPORT_KEYS:
if DEBUG: print(k, lookup[title][k])
v[k] = float(lookup[title][k])
def update_JIF_by_either(values):
issn_lookup = make_lookup()
title_lookup = make_lookup_bytitle()
for v in values:
found = False
if "ISSN" in v:
for issn in v["ISSN"]:
if issn in issn_lookup and not found:
found = True
for k in EXPORT_KEYS:
try:
v[k] = float(issn_lookup[issn][k])
except Exception:
pass
if "container-title" in v and v["container-title"] and not found:
title = v["container-title"].upper()
if title in title_lookup:
found = True
for k in EXPORT_KEYS:
if DEBUG: print(k, title_lookup[title][k])
try:
v[k] = float(title_lookup[title][k])
except Exception:
pass