Skip to content

Instantly share code, notes, and snippets.

@VioletDarkKitty
Last active March 21, 2019 22:16
Show Gist options
  • Save VioletDarkKitty/d26ba9c4a4f70409b8a61098c3ea1df3 to your computer and use it in GitHub Desktop.
Save VioletDarkKitty/d26ba9c4a4f70409b8a61098c3ea1df3 to your computer and use it in GitHub Desktop.
Find the total number of signatures by country outside of the UK for the revoke article 50 petition
#!/bin/python
import urllib2
import json
url = "https://petition.parliament.uk/petitions/241584.json"
response = urllib2.urlopen(url)
json_data = json.loads(response.read())
outside_uk = 0
inside_uk = 0
for country in json_data["data"]["attributes"]["signatures_by_country"]:
if country["code"] != "GB":
outside_uk = outside_uk + country["signature_count"]
else:
inside_uk = country["signature_count"]
percent = float(outside_uk) / inside_uk * 100
print("UK: %d / Other: %d (%f%%)" % (inside_uk, outside_uk, percent))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment