From ee133e4a003defaf5ed8088eb69665bec93da65e Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 2 Oct 2023 23:35:43 +0100 Subject: [PATCH 1/2] Read data dir from config --- .gitignore | 1 + agenda/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fb78f4f..9a2e4a0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ *.py[cod] __pycache__ .mypy_cache +config diff --git a/agenda/__init__.py b/agenda/__init__.py index 2fd6817..2c9e6e2 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -52,16 +52,16 @@ now = datetime.now() today = now.date() now_str = now.strftime("%Y-%m-%d_%H:%M") now_utc = datetime.now(timezone.utc) -data_dir = "/home/edward/lib/data" do_refresh = len(sys.argv) > 1 and sys.argv[1] == "--refresh" next_us_presidential_election = date(2024, 11, 5) next_uk_general_election = date(2024, 5, 2) config = configparser.ConfigParser() -config.read(os.path.join(os.path.dirname(__file__), "config")) +config.read(os.path.join(os.path.dirname(__file__), "..", "config")) access_key = config.get("exchangerate", "access_key") +data_dir = config.get("data", "dir") def get_next_timezone_transition(tz_name: str) -> datetime: From cb993b29e56d8aa9353a82f76f326237b8370a71 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 2 Oct 2023 23:39:37 +0100 Subject: [PATCH 2/2] Remove unused code --- agenda/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agenda/__init__.py b/agenda/__init__.py index 2c9e6e2..9a2e183 100644 --- a/agenda/__init__.py +++ b/agenda/__init__.py @@ -52,7 +52,6 @@ now = datetime.now() today = now.date() now_str = now.strftime("%Y-%m-%d_%H:%M") now_utc = datetime.now(timezone.utc) -do_refresh = len(sys.argv) > 1 and sys.argv[1] == "--refresh" next_us_presidential_election = date(2024, 11, 5) next_uk_general_election = date(2024, 5, 2) @@ -105,7 +104,7 @@ def get_gbpusd() -> Decimal: recent = datetime.strptime(recent_filename, "%Y-%m-%d_%H:%M_GBPUSD.json") delta = now - recent - if not do_refresh and existing and delta < timedelta(hours=6): + if existing and delta < timedelta(hours=6): full = os.path.join(fx_dir, recent_filename) data = json.load(open(full), parse_float=Decimal) if "quotes" in data and "USDGBP" in data["quotes"]: