Skip to content

Commit d31fb52

Browse files
committed
Move config parsing and error handling to config.py
1 parent f002bbc commit d31fb52

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

api.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import tomllib
2-
1+
from config import API_TOKEN, API_KEY, API_URL
32
import requests
43

5-
try:
6-
with open("conf/config.toml", "rb") as f:
7-
config = tomllib.load(f)
8-
except FileNotFoundError:
9-
print("No config found! Please setup your config.toml from the template!")
10-
exit(1)
11-
12-
API_KEY = config["API-CONFIG"]["api_key"]
13-
API_TOKEN = config["API-CONFIG"]["api_token"]
14-
API_URL = config["API-CONFIG"]["api_base_url"]
15-
164
# Set your authentication credentials (API key or bearer token)
175
HEADERS = {
186
"accept": "application/json;charset=UTF-8",

config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import tomllib
2+
3+
try:
4+
with open("conf/config.toml", "rb") as f:
5+
config = tomllib.load(f)
6+
config_exists = True
7+
except FileNotFoundError:
8+
print("No config found! Please setup your config.toml from the template!")
9+
# ToDo: Here we could then ask if the user wants to put in the information and we write it to a config file
10+
# Or if the user wants to supply the file themselves
11+
exit(1)
12+
13+
API_KEY = config["API-CONFIG"]["api_key"]
14+
API_TOKEN = config["API-CONFIG"]["api_token"]
15+
API_URL = config["API-CONFIG"]["api_base_url"]

0 commit comments

Comments
 (0)