diff options
| -rw-r--r-- | python/download_emails.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/python/download_emails.py b/python/download_emails.py index e8c228cd..b9ff318b 100644 --- a/python/download_emails.py +++ b/python/download_emails.py @@ -1,5 +1,6 @@ from datetime import datetime import os +from pathlib import Path from apiclient.discovery import build from apiclient import errors @@ -9,7 +10,6 @@ from oauth2client import client from oauth2client import tools import json import base64 -import pdb import argparse flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() @@ -104,12 +104,15 @@ def main(): credentials = get_credentials() service = build('gmail', 'v1', http=credentials.authorize(Http())) labelsdict = getListLabels(service, 'me') - r = [] + p = Path('quotes') + current_msgs = set([f.name for f in p.iterdir() if f.is_file()]) for msg in ListMessagesWithLabels(service, 'me', labelsdict['swaptions']): - subject, content = msg_content(get_msg(service, 'me', msg['id'])) - with open("quotes/{0}".format(msg['id']), "w") as fh: - fh.write(subject + "\r\n") - fh.write(content) + if msg['id'] not in current_msgs: + subject, content = msg_content(get_msg(service, 'me', msg['id'])) + email = Path("quotes/{0}".format(msg['id'])) + with email.open("w") as fh: + fh.write(subject + "\r\n") + fh.write(content) if __name__ == '__main__': main() |
