Skip to content

Instantly share code, notes, and snippets.

@mhl
Last active August 29, 2015 14:14
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 mhl/06edb1415c6609e1d109 to your computer and use it in GitHub Desktop.
Save mhl/06edb1415c6609e1d109 to your computer and use it in GitHub Desktop.
find constituencies with missing SNP candidates
In [1]: from candidates.static_data import MapItData
In [2]: from candidates.popit import create_popit_api_object
In [3]: api = create_popit_api_object()
In [4]: scottish_cons = [m['id'] for m in MapItData.constituencies_2010.values() if m['country'] == 'S']
In [15]: for post_id in scottish_cons:
....: p = api.posts(str(post_id)).get(embed='membership.person')['result']
....: snp_memberships = [memb for memb in p['memberships'] if memb['person_id']['party_memberships'].get('2015', {}).get('id') == 'party:102']
....: if len(snp_memberships) == 0:
....: print 'https://yournextmp.com/constituency/{0} seemed to have no SNP candidates'.format(post_id)
....:
https://yournextmp.com/constituency/14408 seemed to have no SNP candidates
https://yournextmp.com/constituency/14440 seemed to have no SNP candidates
https://yournextmp.com/constituency/14448 seemed to have no SNP candidates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment