[O] Make config path confiugrable

This commit is contained in:
Hykilpikonna
2021-11-21 23:07:13 -05:00
parent b3e7e3ee38
commit 30aee55a7d
2 changed files with 4 additions and 4 deletions
-1
View File
@@ -13,7 +13,6 @@ import tweepy
from raw_collect.utils import Config, debug, Posting, json_stringify, load_config
from tweepy import API
@dataclass
class User:
id: int
+4 -3
View File
@@ -56,14 +56,15 @@ class Posting:
date: datetime
def load_config() -> Config:
def load_config(path: str = 'config.json5') -> Config:
"""
Load config using JSON5, from either the local file ~/config.json5 or from the environment variable named config.
:param path: Path of the config file (Default: config.json5)
:return: Config object
"""
if os.path.isfile('config.json5'):
with open('config.json5', 'r') as f:
if os.path.isfile(path):
with open(path, 'r', encoding='utf-8') as f:
conf = json5.load(f)
else:
conf = json5.loads(os.getenv('config'))