Skip to content

Instantly share code, notes, and snippets.

@Gapstare
Created February 7, 2021 14:20
Show Gist options
  • Save Gapstare/4a07727860f2885fc2ac95492ceedfe1 to your computer and use it in GitHub Desktop.
Save Gapstare/4a07727860f2885fc2ac95492ceedfe1 to your computer and use it in GitHub Desktop.
pouet.net board stats script
#!/usr/bin/python3
# by El Topo 2021 CC-BY-SA
#
# Requirements: pip3 install phone-iso3166
import urllib.request
import json
import sys
import time
import csv
from phone_iso3166.country import *
if len(sys.argv) < 3:
sys.exit('Usage: %s [start] [end]' % sys.argv[0])
bc = int(sys.argv[1])
bcend = int(sys.argv[2])
baseurl = 'http://api.pouet.net/v1/board/?id='
boards = {None: 0}
print('')
while bc <= bcend:
time.sleep(0.1)
print("\rChecking: %d " % bc, end='')
myurl = baseurl + str(bc)
html = urllib.request.urlopen(myurl).read()
data = json.loads(html.decode('utf-8'))
if 'error' in data:
print('\rNo such BBS.', end='')
else:
if data['board']['id'] == '453':
data['board']['phonenumber'] = '+421-95-xxxxxx'
if data['board']['id'] == '615':
data['board']['phonenumber'] = '+1-215-261-0893'
slask = data['board']['phonenumber']
try:
if phone_country(slask) in boards:
boards[phone_country(slask)] = boards[phone_country(slask)] + 1
else:
boards[phone_country(slask)] = 1
except:
boards[None] = boards[None] + 1
bc = bc + 1
# debug
# print(boards)
with open('boards.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(boards.items())
print('\nWrote data to boards.csv.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment