Browse Source

Removed the need for a specific working directory

master
TGRCDev 5 months ago
parent
commit
f6f98953f0
No known key found for this signature in database GPG Key ID: 3A975199085322C3
3 changed files with 15 additions and 7 deletions
  1. +3
    -1
      __init__.py
  2. +9
    -5
      igdb_utils.py
  3. +3
    -1
      steam_utils.py

+ 3
- 1
__init__.py View File

@ -25,10 +25,12 @@ from requests import HTTPError
import secrets
from datetime import timezone, datetime, timedelta
from itsdangerous import URLSafeSerializer
from os import path
# Load config
def create_app():
config = json.load(open("config.json", "r"))
root_path = path.dirname(__file__)
config = json.load(open(path.join(root_path, "config.json"), "r"))
steam_key = config["steam-key"]
igdb_key = config["igdb-client-id"]
debug = config.get("debug", config.get("DEBUG", False))


+ 9
- 5
igdb_utils.py View File

@ -20,13 +20,16 @@ import sqlite3
from requests.exceptions import ConnectTimeout, ReadTimeout
from typing import Dict, Collection, Any, Mapping, Optional
from datetime import timedelta, datetime, timezone
import os.path
from os import path
api_base = "https://api.igdb.com/v4/"
config = json.load(open("config.json", "r"))
root_path = path.dirname(__file__)
config = json.load(open(path.join(root_path, "config.json"), "r"))
debug = config.get("debug", config.get("DEBUG", False))
db_filename = config.get("igdb-cache-filename", "igdb-cache.sqlite")
if not path.isabs(db_filename):
db_filename = path.join(root_path, db_filename)
create_db_query = """
CREATE TABLE IF NOT EXISTS game_info (
@ -63,7 +66,7 @@ def fetch_and_store_token() -> str:
"expire-time": datetime.now(timezone.utc).timestamp() + token["expires_in"],
"token_type": token["token_type"]
}
token_file = open("bearer-token.json", "w")
token_file = open(path.join(root_path, "bearer-token.json"), "w")
json.dump(token_dict, token_file)
token_file.close()
return token["access_token"]
@ -74,8 +77,9 @@ def fetch_and_store_token() -> str:
def get_or_refresh_token() -> str:
try:
if os.path.exists("bearer-token.json"):
token_file = open("bearer-token.json")
token_path = path.join(root_path, "bearer-token.json")
if path.exists(token_path):
token_file = open(token_path)
token = json.load(token_file)
token_file.close()
if datetime.now(timezone.utc).timestamp() >= token.get("expire-time", 0):


+ 3
- 1
steam_utils.py View File

@ -18,10 +18,12 @@ import requests
from requests.exceptions import ConnectTimeout, ReadTimeout
from typing import Mapping, Any, Collection, Dict, List, Optional
import json
from os import path
api_base = "https://api.steampowered.com/"
config = json.load(open("config.json", "r"))
root_path = path.dirname(__file__)
config = json.load(open(path.join(root_path, "config.json"), "r"))
debug = config.get("debug", config.get("DEBUG", False))
# Fetches public information about a list of Steam users


Loading…
Cancel
Save