aboutsummaryrefslogtreecommitdiffstats
path: root/python/quote_parsing/download_emails.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/quote_parsing/download_emails.py')
-rw-r--r--python/quote_parsing/download_emails.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/python/quote_parsing/download_emails.py b/python/quote_parsing/download_emails.py
index 24d87601..e61f6637 100644
--- a/python/quote_parsing/download_emails.py
+++ b/python/quote_parsing/download_emails.py
@@ -38,8 +38,8 @@ def save_emails(update=True):
last_history_id = int((DATA_DIR / ".lastHistoryId").read_text())
existing_msgs = []
else:
- p = DATA_DIR / "swaptions"
- existing_msgs = set(str(x).split("_")[1] for x in p.iterdir() if x.is_file())
+ p = (DATA_DIR / "swaptions").glob("????-??/*")
+ existing_msgs = set(str(x).split("_")[1] for x in p if x.is_file())
last_history_id = None
gm = GmailMessage()
@@ -63,8 +63,10 @@ def save_emails(update=True):
logger.error("error decoding " + msg['id'])
continue
else:
- email = (DATA_DIR / "swaptions" /
- f"{date:%Y-%m-%d %H-%M-%S}_{msg['id']}")
+ save_dir = DATA_DIR / "swaptions" / f"{date:%Y-%m}"
+ if not save_dir.exists():
+ save_dir.mkdir()
+ email = save_dir / f"{date:%Y-%m-%d %H-%M-%S}_{msg['id']}"
with email.open("w") as fh:
fh.write(subject + "\r\n")
fh.write(content)