Skip to content

Instantly share code, notes, and snippets.

@linkviii
Created April 17, 2023 06:15
Show Gist options
  • Save linkviii/50da058ca071df33f28679e1812cee73 to your computer and use it in GitHub Desktop.
Save linkviii/50da058ca071df33f28679e1812cee73 to your computer and use it in GitHub Desktop.
# Go to https://www.twitch.tv/wallet?tab=bits-usage-history
# Hold down 'page down' key until nothing more loads
# Right click table -> Inspect element
# Find the table tag
# right click -> edit as html
# ctrl-a, ctrl-c -> save as foo.html
from bs4 import BeautifulSoup
from pathlib import Path
from pprint import pprint
import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
doc = Path('foo.html').read_text()
soup = BeautifulSoup(doc)
rows = soup.find('tbody').find_all('tr')
raw_data = []
data_by_channel = {}
for row in rows:
ds = row.find_all('td')
ss = [it.text.strip() for it in ds]
val = {"date": ss[0],
"channel": ss[1],
"type": ss[2],
"amount": ss[3]}
raw_data.append(val)
tmp = data_by_channel.get(val['channel'], [])
tmp.append(val)
data_by_channel[val['channel']] = tmp
totals = {}
for channel, l in data_by_channel.items():
s = 0
for val in l:
s += locale.atof(val['amount'].split()[0])
totals[channel] = s / 100
pprint(sorted(totals.items(), key=lambda x: x[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment