Skip to content

Instantly share code, notes, and snippets.

@pjsier pjsier/mcomm_search.py

Last active Aug 29, 2015
Embed
What would you like to do?
Quick script to check if names on list are Michigan undergraduates using MCommmunity open API. Used to check against voter registration data
import urllib2
import csv, json
def respondAndParse(name_list):
stu_list = []
for named in name_list:
for name in named:
query_string = name.replace(" ", "%20")
URLrecord = "https://mcommunity.umich.edu/mcPeopleService/people/search/" + query_string
try:
siteResponse = urllib2.urlopen(URLrecord).read()
personResponse = json.loads(siteResponse)
for person in personResponse['person']:
if "aliases" in person and "affiliation" in person:
for alias in person['aliases']:
if (name == alias) and (" - Student" in str(person['affiliation'])) and ("Flint" not in str(person['affiliation'])) and ("Dearborn" not in str(person['affiliation'])):
print name
stu_list.append(name)
except:
pass
return stu_list
if __name__ == "__main__":
fileName = "aa_stu_names.csv"
with open(fileName, "rU") as f:
csvreader = csv.reader(f)
name_list = list(csvreader)
student_list = respondAndParse(name_list)
with open("aa_stu_voters.csv", "ab") as f:
csvwriter = csv.writer(f)
for student in student_list:
csvwriter.writerow([student])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.