Skip to content

Instantly share code, notes, and snippets.

@parsingphase

parsingphase/sum-sigs.py

Last active Jun 25, 2020
Embed
What would you like to do?
Petitions.parliament.uk counter script
#!/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))
@parsingphase

This comment has been minimized.

Copy link
Owner Author

@parsingphase parsingphase commented Mar 21, 2019

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

@parsingphase

This comment has been minimized.

Copy link
Owner Author

@parsingphase parsingphase commented Mar 21, 2019

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
You can’t perform that action at this time.