forked from Billingegroup/rg-db-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_uni.py
150 lines (141 loc) · 4.09 KB
/
get_uni.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
from pprint import pprint
import pandas as pd
us_states = {
"AK": "Alaska",
"AL": "Alabama",
"AR": "Arkansas",
"AS": "American Samoa",
"AZ": "Arizona",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DC": "District of Columbia",
"DE": "Delaware",
"FL": "Florida",
"GA": "Georgia",
"GU": "Guam",
"HI": "Hawaii",
"IA": "Iowa",
"ID": "Idaho",
"IL": "Illinois",
"IN": "Indiana",
"KS": "Kansas",
"KY": "Kentucky",
"LA": "Louisiana",
"MA": "Massachusetts",
"MD": "Maryland",
"ME": "Maine",
"MI": "Michigan",
"MN": "Minnesota",
"MO": "Missouri",
"MP": "Northern Mariana Islands",
"MS": "Mississippi",
"MT": "Montana",
"NA": "National",
"NC": "North Carolina",
"ND": "North Dakota",
"NE": "Nebraska",
"NH": "New Hampshire",
"NJ": "New Jersey",
"NM": "New Mexico",
"NV": "Nevada",
"NY": "New York",
"OH": "Ohio",
"OK": "Oklahoma",
"OR": "Oregon",
"PA": "Pennsylvania",
"PR": "Puerto Rico",
"RI": "Rhode Island",
"SC": "South Carolina",
"SD": "South Dakota",
"TN": "Tennessee",
"TX": "Texas",
"UT": "Utah",
"VA": "Virginia",
"VI": "Virgin Islands",
"VT": "Vermont",
"WA": "Washington",
"WI": "Wisconsin",
"WV": "West Virginia",
"WY": "Wyoming",
}
unis = [
"montreal",
"Vanderbilt University",
"University of Wisconsin - Milwaukee",
"Arizona State University",
"Ohio University - Main Campus",
"University of Illinois at Urbana-Champaign",
"Northwestern University",
"Lehigh University",
"Rutgers, The State University of New Jersey",
"Drexel University",
"University of California - Davis",
"Kent State University",
"California Institute of Technology",
]
regolith_info = {
"city": "Institution_City",
"name": "Institution_Name",
"state": "Institution_State",
"zip": "Institution_Zip",
}
df = pd.read_csv("Accreditation_04_2017.csv")
data = df.to_dict("index")
output = {}
for u in unis:
for n, d in data.items():
if u.lower() == d.get("Institution_Name", "").lower():
dd = {"country": "USA", "aka": []}
dd.update({k: data[n][v] for k, v in regolith_info.items()})
if len(dd["name"].split("University")[0]) > 1:
dd["aka"].append(
dd["name"].split(",")[0].split("University")[0].strip()
)
dd["aka"].append(dd["aka"][0].lower())
data_id = (
dd["name"]
.split("University")[0]
.split(",")[0]
.strip()
.lower()
.replace(" ", "")
)
dd["zip"] = str(dd["zip"])
if (
"state" in dd["name"].lower()
and us_states[dd["state"]] in dd["name"]
):
data_id = "".join(
[a[0] for a in dd["name"].split(" ")]
).lower()
if dd["name"].startswith("University of " ):
data_id = (
"".join([a[0] for a in dd["name"].split(" of ")])
+ dd["city"]
).lower()
dd["aka"].append(
("".join([a[0] for a in dd["name"].split(" of ")])).upper()
+ " "
+ dd['name'].rsplit(' ')[-1]
)
# DIRTY HACK
if "University of Illinois" in dd["name"]:
data_id = "uiuc"
dd['aka'].append('UIUC')
if dd["name"] == "California Institute of Technology":
data_id = "caltech"
dd['aka'].append('CalTech')
if "rutgers" in dd["name"].lower():
data_id = "rutgers"
if (
"u" not in data_id
and "Institute of Technology" not in dd["name"]
):
data_id += "u"
output.update({data_id: dd})
pprint(output)
from ruamel.yaml import YAML
yaml = YAML()
with open("unis.yaml", "w") as f:
yaml.dump(output, f)