2020-12-20 00:08:09 +00:00
|
|
|
#interfaces with onomancer
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import json
|
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 = "generateStats/"
|
|
|
|
|
|
|
|
def get_stats(username):
|
2020-12-20 01:26:05 +00:00
|
|
|
#check database for cached name first
|
2020-12-20 03:14:45 +00:00
|
|
|
scream = db.get_soulscream(username)
|
|
|
|
if scream is not None:
|
|
|
|
return scream
|
2020-12-20 01:26:05 +00:00
|
|
|
|
2020-12-20 03:14:45 +00:00
|
|
|
#yell at onomancer if not in cache or too old
|
2020-12-20 00:08:09 +00:00
|
|
|
response = requests.get(onomancer_url + name_stats_hook + username)
|
2020-12-20 03:14:45 +00:00
|
|
|
print("yelled at onomancer")
|
2020-12-20 00:08:09 +00:00
|
|
|
if response.status_code == 200:
|
2020-12-20 03:14:45 +00:00
|
|
|
db.cache_soulscream(username, response.json()["soulscream"])
|
|
|
|
return response.json()["soulscream"]
|