Skip to content

Instantly share code, notes, and snippets.

@andylolz
Last active August 29, 2015 14:16
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/8dba04a31ea06f4ab946 to your computer and use it in GitHub Desktop.
Save andylolz/8dba04a31ea06f4ab946 to your computer and use it in GitHub Desktop.
MPs not standing for re-election in 2015. (The year of each MP’s earliest parliamentary membership is also shown)
import requests
import time
tmpl = "http://yournextmp.popit.mysociety.org/api/v0.1/search/persons?q=_missing_:standing_in.2015.post_id%20AND%20identifiers.scheme:%22uk.org.publicwhip%22&page={}"
more = True
page = 0
mps = []
while more:
page += 1
print 'Current page: %d' % page
j = requests.get(tmpl.format(page)).json()
more = j['has_more']
mps += j['result']
time.sleep(0.5)
for x in mps:
if x["standing_in"] is None or "2015" not in x["standing_in"]:
continue
success = False
for b in x["identifiers"]:
if b["scheme"] == "uk.org.publicwhip":
if b["identifier"].split("/")[-1] in z:
success = True
if not success:
continue
for i, v in enumerate(x["versions"]):
if "2015" not in v["data"]["standing_in"] or v["data"]["standing_in"]["2015"] is not None:
source = x["versions"][i-1]["information_source"]
# TODO: check source is a valid URL
print " * [%s](https://yournextmp.com/person/%s) (%s, %s) [source](%s)" % (x["name"], x["id"], x["party_memberships"]["2010"]["name"], x["standing_in"]["2010"]["name"], source)
break
@andylolz
Copy link
Author

andylolz commented Mar 5, 2015

Currently unknown:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment