Skip to content

Instantly share code, notes, and snippets.

@GabeMillikan
Created June 13, 2023 19:38
Show Gist options
  • Save GabeMillikan/5612c5486f6450e838d461b23300cb04 to your computer and use it in GitHub Desktop.
Save GabeMillikan/5612c5486f6450e838d461b23300cb04 to your computer and use it in GitHub Desktop.
Count the number of cs:go cases i've opened
# SETUP:
# 1. install python from https://python.org with the default settings
# 2. run the following command for your operating system:
# - MacOS/Linux: `python3 -m pip install beautifulsoup4 lxml pyperclip`
# - Windows: `py -m pip install beautifulsoup4 lxml pyperclip`
#
# USAGE:
# 1. scroll to the bottom of this page: https://store.steampowered.com/account/history/
# 2. click "LOAD MORE TRANSACTIONS"
# 3. scroll back to the top
# 4. right click on the "Date" text in the column header -> inspect
# 5. a few elements above, right click on "wallet_history_table" -> copy -> Outer HTML
# 6. run this script using the following command for your operating system:
# - MacOS/Linux: `python3 csgo_case_key_counter.py`
# - Windows: `py csgo_case_key_counter.py`
#
# Note that some cases use the same keys. For example,
# all of the 3 of the CS:GO Weapon Cases use the same key "CS:GO Case Key".
# It is not possible to differentiate the three.
import pyperclip
import re
import bs4
totals: dict[str, int] = {}
html = pyperclip.paste()
soup = bs4.BeautifulSoup(html, features="lxml")
rows = soup.select("tr.wallet_table_row")
for row in rows:
items = row.select_one(".wht_items").text.strip().splitlines()[-1].strip()
match = re.search(r'^(\d+)?([\w\s:]+ Case Key)', items)
if not match:
continue
count = int(match.group(1) or "1")
case = match.group(2).strip()
totals.setdefault(case, 0)
totals[case] += count
totals = dict(sorted(totals.items(), key=lambda pair: pair[1], reverse=True))
print(f"In total, you opened {sum(totals.values())} cases.")
for case, count in totals.items():
print(f" * {count: 4d}x {case}{'s' if count != 1 else ''}")
@GabeMillikan
Copy link
Author

GabeMillikan commented Jun 13, 2023

usage.mp4

@GabeMillikan
Copy link
Author

Updated script also counts your steam wallet deposits:

import pyperclip
import re
import bs4

case_keys: dict[str, int] = {}
purchased_wallet_credit: float = 0.0

html = pyperclip.paste()
soup = bs4.BeautifulSoup(html, features="lxml")

rows = soup.select("tr.wallet_table_row")
for row in rows:
    items = row.select_one(".wht_items").text.strip().splitlines()[-1].strip()

    if (match := re.search(r'^(\d+)?([\w\s:]+ Case Key)', items)):
        if not match:
            continue

        count = int(match.group(1) or "1")
        case = match.group(2).strip()

        case_keys.setdefault(case, 0)
        case_keys[case] += count

    if (match := re.search(r'^Purchased \$([\d.]+) Wallet Credit', items)):
        purchased_wallet_credit += float(match.group(1))

case_keys = dict(sorted(case_keys.items(), key=lambda pair: pair[1], reverse=True))

print(f"In total, you've deposited ${purchased_wallet_credit:.2f} into your steam wallet. (does not count game purchases)")
print(f"In total, you opened {sum(case_keys.values())} cases.")
for case, count in case_keys.items():
    print(f"  * {count: 4d}x {case}{'s' if count != 1 else ''}")

@GabeMillikan
Copy link
Author

Bitskins profit calculator:

"""
1. Ctrl+A -> Ctrl+C on this page https://bitskins.com/history?type=wallet
2. run this script

You might need to repeat this process multiple times if you have more than 1 page of transaction history.
"""

import pyperclip
import re

data = pyperclip.paste()
deposited = 0
withdrawn = 0

for n in re.findall(r"USD\s*((?:\+|-)[\d,.]+)", data):
    amount = float(n.replace(",", ""))
    if amount > 0:
        deposited += amount
    else:
        withdrawn -= amount

print(f"{deposited = :.2f}")
print(f"{withdrawn = :.2f}")

print(f"Overall {'profit' if withdrawn >= deposited else 'loss'}: ${abs(withdrawn - deposited):.2f}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment