From 30aee55a7d03f04550dd51af3d43ce187fd8f9ca Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 21 Nov 2021 23:07:13 -0500 Subject: [PATCH] [O] Make config path confiugrable --- src/raw_collect/twitter.py | 1 - src/raw_collect/utils.py | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/raw_collect/twitter.py b/src/raw_collect/twitter.py index c759783..8c6464b 100644 --- a/src/raw_collect/twitter.py +++ b/src/raw_collect/twitter.py @@ -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 diff --git a/src/raw_collect/utils.py b/src/raw_collect/utils.py index a864399..1f4b78a 100644 --- a/src/raw_collect/utils.py +++ b/src/raw_collect/utils.py @@ -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'))