Skip to content

Instantly share code, notes, and snippets.

@andylolz
Created February 2, 2015 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andylolz/61be99425dd3caf3d7ad to your computer and use it in GitHub Desktop.
Save andylolz/61be99425dd3caf3d7ad to your computer and use it in GitHub Desktop.
Hacky YNMP script to find Green Party candidates in Scotland
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