Last active
March 21, 2019 22:16
-
-
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
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
#!/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