Skip to content

Instantly share code, notes, and snippets.

@pjsier
Last active August 29, 2015 14:11
Show Gist options
  • Save pjsier/f9a8ecb68f82128699fd to your computer and use it in GitHub Desktop.
Save pjsier/f9a8ecb68f82128699fd to your computer and use it in GitHub Desktop.
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