aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/download_emails.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/python/download_emails.py b/python/download_emails.py
index 33a78b85..76e5ddbc 100644
--- a/python/download_emails.py
+++ b/python/download_emails.py
@@ -142,11 +142,12 @@ def save_emails(update=True):
if update:
try:
- last_history_id = int((DATA_DIR / ".lastHistoryID").read_text())
+ last_history_id = int((DATA_DIR / ".lastHistoryId").read_text())
except FileNotFoundError:
sys.exit()
existing_msgs = []
else:
+ p = DATA_DIR / "swaptions"
existing_msgs = set(str(x).split("_")[1] for x in p.iterdir() if x.is_file())
last_history_id = None
@@ -155,7 +156,7 @@ def save_emails(update=True):
continue
try:
message = GmailMessage.from_id(msg['id'])
- print(message.history_id)
+ logging.info(message.history_id)
subject = message['subject']
date = parsedate_to_datetime(message['date'])
if date.tzinfo is None:
@@ -163,7 +164,7 @@ def save_emails(update=True):
date = date.astimezone(timezone('America/New_York'))
body = message.get_body('plain')
content = body.get_content()
- except (KeyError, UnicodeDecodeError) as e:
+ except (KeyError, UnicodeDecodeError, AttributeError) as e:
logging.error("error decoding " + msg['id'])
continue
else:
@@ -174,15 +175,10 @@ def save_emails(update=True):
fh.write(content)
try:
new_history_id = message.history_id
- (DATA_DIR / ".lastHistoryID").write_text(message.history_id)
+ (DATA_DIR / ".lastHistoryId").write_text(message.history_id)
except UnboundLocalError:
pass
- # for msg in ListMessagesWithLabels(GmailMessage._service, 'me', labelsdict['swaptions']):
- # if msg['id'] not in current_msgs:
- # try:
-
-
if __name__ == '__main__':
try:
save_emails()