Skip to content

Instantly share code, notes, and snippets.

@bzimor
Created July 4, 2023 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bzimor/0817950826b19c7f89d22772a7ff96b2 to your computer and use it in GitHub Desktop.
Save bzimor/0817950826b19c7f89d22772a7ff96b2 to your computer and use it in GitHub Desktop.
Gained items per Crime skill in Crime 2.0
import urllib
import time
import collections
import requests
TORN_API_TOKEN = '<YOUR FULL ACCESS TORN API TOKEN>'
def get_data_from_torn(token, section, selections='', id=''):
if id:
id = str(id)
url = f'https://api.torn.com/{section}/{id}?selections={selections}&key={token}'
resp = requests.get(url)
result = resp.json()
return result
def get_log_api(log_id, to=''):
url = f'https://api.torn.com/user/?selections=log&to={to}&log={log_id}&key={TORN_API_TOKEN}'
resp = requests.get(url)
result = resp.json()
return result
def parse_crime_logs(item_levels, last_level, to=''):
crime = {}
log_id = "9005,9020"
result = get_log_api(log_id, to=to)
if result["log"]:
last_timestamp = ""
for r in result["log"].values():
if r["log"] == 9005 and r["data"]["crime"] == "search for cash":
last_level = r["data"]["skill_level"]
elif r["log"] == 9020:
for item in r["data"]["items_gained"].keys():
item_levels[item] = last_level
last_timestamp = r["timestamp"]
parse_crime_logs(item_levels, last_level, last_timestamp)
return item_levels
def main():
item_levels = {}
item_ids = parse_crime_logs(item_levels, 100)
items = get_data_from_torn(TORN_API_TOKEN, "torn", "items")
result = {}
for k, v in item_ids.items():
if v not in result:
result[v] = []
result[v].append(items["items"][k]["name"])
result = collections.OrderedDict(sorted(result.items()))
for lvl, item_names in result.items():
print("Skill - ", lvl)
for i in item_names:
print("- ", i)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment