remove my own details from repo. use config

This commit is contained in:
Greg Gauthier 2025-04-12 18:32:46 +01:00
parent 03a65a2244
commit 9fe3937d88
2 changed files with 9 additions and 13 deletions

View File

@ -11,7 +11,8 @@ class Config:
Args: Args:
config_path (str): Path to the TOML configuration file config_path (str): Path to the TOML configuration file
""" """
self.project_root = Path(__file__).resolve().parent config_dir = Path(__file__).resolve().parent
self.project_root = config_dir.parent
self.config_path = self.project_root / config_file self.config_path = self.project_root / config_file
self._load_config() self._load_config()
@ -28,8 +29,6 @@ class Config:
self.api_key_file = self.project_root.joinpath( self.api_key_file = self.project_root.joinpath(
"keys", config_data["api"]["key_file"]) "keys", config_data["api"]["key_file"])
self.host = config_data["api"]["host"] self.host = config_data["api"]["host"]
# Load API key
self._load_api_key() self._load_api_key()
def _load_api_key(self): def _load_api_key(self):
@ -37,8 +36,8 @@ class Config:
if not self.api_key_file.exists(): if not self.api_key_file.exists():
raise FileNotFoundError(f"API key file not found: {self.api_key_file}") raise FileNotFoundError(f"API key file not found: {self.api_key_file}")
with open(self.api_key_file, 'r') as key_file: with (open(self.api_key_file, 'r') as key_file):
self.api_key = key_file.read().strip() self.api_key = key_file.read().strip().replace('\n', '').replace('\r', '')
def get_headers(self): def get_headers(self):
"""Return headers for API requests""" """Return headers for API requests"""

View File

@ -1,15 +1,12 @@
import requests import requests
from config.configuration import Config
host = 'forum.lunduke.com' cfg = Config()
username = 'gmgauthier'
url = f"https://{host}/posts.json"
with open('../keys/cli_key.txt', 'r') as key:
api_key = key.read()
api_key = api_key.replace('\n', '').replace('\r', '')
username = cfg.username
url = cfg.get_api_url(endpoint='/site.json')
api_key = cfg.api_key
headers={ headers={
"api_key": api_key, "api_key": api_key,