matteo-the-prestige/onomancer.py

29 lines
835 B
Python
Raw Normal View History

2020-12-20 00:08:09 +00:00
#interfaces with onomancer
import requests, json, urllib
2020-12-20 01:26:05 +00:00
import database as db
2020-12-20 00:08:09 +00:00
onomancer_url = "https://onomancer.sibr.dev/api/"
name_stats_hook = "generateStats2?name="
2020-12-20 00:08:09 +00:00
def get_stats(name):
player = db.get_stats(name)
if player is not None:
return player #returns json_string
#yell at onomancer if not in cache or too old
response = requests.get(onomancer_url + name_stats_hook + urllib.parse.quote_plus(name))
if response.status_code == 200:
stats = json.dumps(response.json())
db.cache_stats(name, stats)
return stats
def get_scream(username):
scream = db.get_soulscream(username)
if scream is not None:
return scream
else:
scream = json.loads(get_stats(username))["soulscream"]
db.cache_soulscream(username, scream)
return scream