add alive_bar to requirements

This commit is contained in:
Maximilian Keßler 2023-05-14 14:04:57 +02:00
parent 357e98b8db
commit 258b804576
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 11 additions and 5 deletions

View file

@ -5,3 +5,4 @@ termcolor
more_itertools more_itertools
psycopg2 psycopg2
alive_progress alive_progress
argparse

View file

@ -1,31 +1,36 @@
import json import json
import requests import requests
import requests_cache import requests_cache
from log_setup import logger
# Cache all requests to site to reduce traffic and latency # Cache all requests to site to reduce traffic and latency
session = requests_cache.CachedSession('hanab.live') session = requests_cache.CachedSession('hanab.live')
def get(url): def get(url, refresh=False):
# print("sending request for " + url) # print("sending request for " + url)
query = "https://hanab.live/" + url query = "https://hanab.live/" + url
response = session.get(query) logger.debug("GET {}".format(query))
response = session.get(query, force_refresh=refresh)
if not response: if not response:
raise RuntimeError("Failed to get request {} from hanab.live".format(query)) logger.error("Failed to get request {} from hanab.live".format(query))
return None
if not response.status_code == 200: if not response.status_code == 200:
return None return None
if "application/json" in response.headers['content-type']: if "application/json" in response.headers['content-type']:
return json.loads(response.text) return json.loads(response.text)
def api(url):
def api(url, refresh=False):
link = "api/v1/" + url link = "api/v1/" + url
if "?" in url: if "?" in url:
link += "&" link += "&"
else: else:
link += "?" link += "?"
link += "size=100" link += "size=100"
return get(link) return get(link, refresh)
def replay(seed): def replay(seed):
r = api("seed/" + str(seed)) r = api("seed/" + str(seed))