Last active
June 25, 2020 09:11
-
-
Save parsingphase/ea627bbba73b6e0ec4293863f90813a2 to your computer and use it in GitHub Desktop.
Petitions.parliament.uk counter script
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
#!/usr/bin/env python3 | |
import json | |
file_path = '241584.json' | |
with open(file_path, 'r') as f: | |
data = json.loads(''.join(f.readlines())) | |
sbyc = data['data']['attributes']['signatures_by_country'] | |
uk_codes = ['GG', 'GI', 'BAT', 'IM', 'SH', 'GB', 'JE'] | |
uk_count = 0 | |
other_count = 0 | |
for row in sbyc: | |
in_uk = row['code'] in uk_codes | |
print('%s: %s: %d %s' % (row['code'], row['name'], row['signature_count'], '*' if in_uk else '')) | |
if in_uk: | |
uk_count += row['signature_count'] | |
else: | |
other_count += row['signature_count'] | |
total = uk_count + other_count | |
print('--------') | |
print('Counted as UK: ', uk_codes) | |
print('UK: %d (%.2f%%)' % (uk_count, uk_count * 100 / total)) | |
print('Other: %d (%.2f%%)' % (other_count, other_count * 100 / total)) |
Last run output:
...
--------
Counted as UK: ['GG', 'GI', 'BAT', 'IM', 'SH', 'GB', 'JE']
UK: 1157742 (96.32%)
Other: 44187 (3.68%)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: download the JSON export of a petition (eg https://petition.parliament.uk/petitions/241584.json), revise
file_path
in line 5 to point to it, roll eyes at the trolls crying fraud.Run with python 3:
python3 sum-sigs.py