-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlCaller.py
159 lines (124 loc) · 5.49 KB
/
sqlCaller.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import pandas as pd
from tqdm import tqdm
import peewee
from peewee import *
import sqlCredentials
db = MySQLDatabase(sqlCredentials.name, user=sqlCredentials.user, passwd=sqlCredentials.password, port=sqlCredentials.port)
class BaseModel(Model):
class Meta:
database = db
class Publications(BaseModel):
authid = IntegerField(db_column='authid', null=False)
authname = TextField(db_column='authname', null=False)
title = TextField(db_column='title', null=False, primary_key=True)
authors = TextField(db_column='authors', null=False)
year = IntegerField(db_column='year', null=False)
journal = TextField(db_column='journal', null=False)
source = TextField(db_column='source', null=False)
raw = TextField(db_column='raw', null=False)
class Citations(BaseModel):
title = TextField(db_column='title', null=False)
year = IntegerField(db_column='year', null=False)
journal = TextField(db_column='journal', null=False)
citation_count = IntegerField(db_column='citation_count', null=False)
class CVPersonalWebsites(BaseModel):
class Meta:
db_table = 'CV_personal_websites'
authname = TextField(db_column='authname', null=False)
website1_url = TextField(db_column='website1_url', null=False)
website2_url = TextField(db_column='website2_url', null=False)
website3_url = TextField(db_column='website3_url', null=False)
website4_url = TextField(db_column='website4_url', null=False)
website5_url = TextField(db_column='website5_url', null=False)
website1_raw = TextField(db_column='website1_raw', null=False)
website2_raw = TextField(db_column='website2_raw', null=False)
website3_raw = TextField(db_column='website3_raw', null=False)
website4_raw = TextField(db_column='website4_raw', null=False)
website5_raw = TextField(db_column='website5_raw', null=False)
full_name = TextField(db_column="full_name", null=False)
publication = TextField(db_column="publication", null=False)
def populate_publications(file_name):
data = pd.read_csv(file_name)
data = data.fillna(-1)
for index, row in tqdm(data.iterrows()):
authid = row['UID']
authname = row["NameFirst"] + " " + row["NameLast"]
title = row["article_title"]
authors = row["authors"]
year = row["year"]
journal = row["journal"]
source = "Google Scholar"
raw = row["reference"]
try:
Publications.create(authid=authid, authname=authname, title=title, authors=authors, year=year, journal=journal, source=source, raw=raw)
except Exception as e:
print(e)
print("Interrupted at index: " + str(index))
def populate_citations(file_name):
data = pd.read_csv(file_name)
data = data.fillna(-1)
for index, row in tqdm(data.iterrows()):
title = row['article_title']
year = row['year']
journal = row['journal']
citation_count = row['citations']
try:
Citations.create(title=title, year=year, journal=journal, citation_count=citation_count)
except Exception as e:
print(e)
print("Interrupted at index: " + str(index))
def populate_CVs(file_name):
data = pd.read_csv(file_name)
data = data.fillna(-1)
for index, row in tqdm(data.iterrows()):
authname = row['Input.name']
website1_url = row['top_1_url']
website2_url = row['top_2_url']
website3_url = row['top_3_url']
website4_url = row['top_4_url']
website5_url = row['top_5_url']
website1_raw = row['top_1_raw']
website2_raw = row['top_2_raw']
website3_raw = row['top_3_raw']
website4_raw = row['top_4_raw']
website5_raw = row['top_5_raw']
publication = row['unconfirmed_publications']
name = row["Input.name"]
name_split = name.split('-')
# Handle cases like "Donald-Mac Lump"
if len(name_split) == 2:
full_name = " ".join(name_split)
else:
initials = row["Google Scholar Middle Initial"]
if isinstance(initials, int):
full_name = name
else:
middle = initials[1]
first = name_split[0].split()[0]
last = name_split[0].split()[1]
full_name = first + " " + middle + " " + last
try:
CVPersonalWebsites.create(authname=authname,
website1_url=website1_url,
website2_url=website2_url,
website3_url=website3_url,
website4_url=website4_url,
website5_url=website5_url,
website1_raw=website1_raw,
website2_raw=website2_raw,
website3_raw=website3_raw,
website4_raw=website4_raw,
website5_raw=website5_raw,
publication=publication,
full_name=full_name)
except Exception as e:
print(e)
print("Interrupted at index: " + str(index))
def main():
db.connect()
# populate_publications('NESCent_publications/nescent_ID.csv')
# populate_citations('Stage_1/NESCent_ID_citations.csv')
# populate_CVs("Stage_2/turk_grouped.csv")
db.close()
if __name__ == "__main__":
main()