2020-12-20 00:08:09 +00:00
|
|
|
#interfaces with onomancer
|
|
|
|
|
2020-12-20 06:31:48 +00:00
|
|
|
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/"
|
2020-12-20 06:31:48 +00:00
|
|
|
name_stats_hook = "generateStats2?name="
|
2020-12-20 00:08:09 +00:00
|
|
|
|
2020-12-20 12:25:25 +00:00
|
|
|
def get_stats(name):
|
|
|
|
#yell at onomancer if not in cache or too old
|
|
|
|
response = requests.get(onomancer_url + name_stats_hook + urllib.parse.quote_plus(name))
|
2020-12-21 05:23:02 +00:00
|
|
|
if response.status_code == 200:
|
2020-12-20 12:25:25 +00:00
|
|
|
return response.json()
|
|
|
|
|
|
|
|
def get_scream(username):
|
2020-12-20 03:14:45 +00:00
|
|
|
scream = db.get_soulscream(username)
|
|
|
|
if scream is not None:
|
|
|
|
return scream
|
2020-12-20 12:25:25 +00:00
|
|
|
else:
|
|
|
|
scream = get_stats(username)["soulscream"]
|
|
|
|
db.cache_soulscream(username, scream)
|
|
|
|
return scream
|