Created
February 2, 2015 12:54
-
-
Save andylolz/61be99425dd3caf3d7ad to your computer and use it in GitHub Desktop.
Hacky YNMP script to find Green Party candidates in Scotland
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import requests | |
''' | |
Check for Green Party candidates in Scotland (they are probably | |
supposed to be Scottish Green Party candidates) | |
''' | |
r = requests.get('http://mapit.mysociety.org/areas/WMC') | |
j = r.json() | |
scottish_ids = [id_ for id_, val in j.items() if val['country_name'] == 'Scotland'] | |
tmpl = 'http://yournextmp.popit.mysociety.org/api/v0.1/posts/%s?embed=membership.person' | |
# Fetch all the data | |
data = [] | |
for constituency_id in scottish_ids: | |
time.sleep(0.5) | |
r = requests.get(tmpl % constituency_id) | |
data.append(r.json()) | |
# Search for Green Party instances | |
for constituency in data: | |
for candidate in constituency['result']['memberships']: | |
parties = [party['name'] for party in candidate['person_id']['party_memberships'].values()] | |
if 'Green Party' in parties: | |
print "Looks like there might be a problem in %s" % constituency['result']['area']['id'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment