-
-
Save lesp/d14cc5d1d3f381bc1090ac131ad2beaa to your computer and use it in GitHub Desktop.
petition watcher
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
import requests | |
from time import sleep | |
url = "https://petition.parliament.uk/petitions/241584/count.json" | |
def get_count(): | |
count = None | |
while True: | |
r = requests.get(url) | |
if r: | |
return r.json()['signature_count'] | |
else: | |
print("Could not reach petition site") | |
c = get_count() | |
print("{:,} signatures".format(c)) | |
while True: | |
sleep(60) | |
n = get_count() | |
print("{:,} signatures, {:,} new signatures in last minute".format(n, n-c)) | |
c = n |
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
import requests | |
url = "https://petition.parliament.uk/petitions/241584.json" | |
sbc = requests.get(url).json()['data']['attributes']['signatures_by_country'] | |
for d in sbc: | |
print("{name}: {signature_count:,}".format(**d)) | |
print("Total: {:,}".format(sum(d['signature_count'] for d in sbc))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed the url so that it is shorter, now it is https://petition.parliament.uk/petitions/241584/count.json
Changed requests.get to just look for signature_count key.