Spaces:
Building
Building
# shared.py | |
import aiohttp | |
user_cash = {} | |
user_bets = {} | |
async def fetch_nhl_scores(): | |
async with aiohttp.ClientSession() as session: | |
async with session.get("https://nhl-score-api.herokuapp.com/api/scores/latest") as response: | |
return await response.json() | |
def load_database(): | |
global user_cash | |
try: | |
with open("database.txt", "r") as f: | |
for line in f: | |
parts = line.strip().split() | |
if len(parts) == 2 and parts[1].startswith("cash(") and parts[1].endswith(")"): | |
user_id = int(parts[0]) | |
cash = int(parts[1][5:-1]) | |
user_cash[user_id] = cash | |
except FileNotFoundError: | |
print("No database found. Creating a new one.") | |
load_database() |