diff options
| -rw-r--r-- | python/collateral_calc.py | 5 | ||||
| -rw-r--r-- | python/download_emails.py | 5 | ||||
| -rw-r--r-- | python/gmail_helpers.py | 12 |
3 files changed, 12 insertions, 10 deletions
diff --git a/python/collateral_calc.py b/python/collateral_calc.py index ab52db5c..836c68ee 100644 --- a/python/collateral_calc.py +++ b/python/collateral_calc.py @@ -77,9 +77,10 @@ def download_sftp_files(d=None, def download_ms_emails_from_gmail(): DATA_DIR = DAILY_DIR / "MS_reports" from download_emails import GmailMessage - for msg in GmailMessage.List_msg_ids('Globeop/Operations'): + gm = GmailMessage() + for msg in gm.list_msg_ids('Globeop/Operations'): try: - message = GmailMessage.from_id(msg['id']) + message = gm.from_id(msg['id']) subject = message['subject'] if 'SERCX **Daily' in subject: for attach in message.iter_attachments(): diff --git a/python/download_emails.py b/python/download_emails.py index 9072f4ec..cf738e9e 100644 --- a/python/download_emails.py +++ b/python/download_emails.py @@ -43,11 +43,12 @@ def save_emails(update=True): existing_msgs = set(str(x).split("_")[1] for x in p.iterdir() if x.is_file()) last_history_id = None - for msg in GmailMessage.list_msg_ids('swaptions', last_history_id): + gm = GmailMessage() + for msg in gm.list_msg_ids('swaptions', last_history_id): if msg['id'] in existing_msgs: continue try: - message = GmailMessage.from_id(msg['id']) + message = gm.from_id(msg['id']) logging.info(message.history_id) subject = message['subject'] date = parsedate_to_datetime(message['date']) diff --git a/python/gmail_helpers.py b/python/gmail_helpers.py index ff7c49bd..f916f614 100644 --- a/python/gmail_helpers.py +++ b/python/gmail_helpers.py @@ -145,17 +145,17 @@ class GmailMessage(EmailMessage): except errors.HttpError as error: print('An error occurred: %s' % error) - @staticmethod - def list_msg_ids(label, start_history_id=None): + @classmethod + def list_msg_ids(cls, label, start_history_id=None): if start_history_id is not None: - return ListHistory(GmailMessage._service, + return ListHistory(cls._service, 'me', - label_id=GmailMessage._labels[label], + label_id=cls._labels[label], start_history_id=start_history_id) else: - return ListMessagesWithLabels(GmailMessage._service, + return ListMessagesWithLabels(cls._service, 'me', - label_ids=[GmailMessage._labels[label]]) + label_ids=[cls._labels[label]]) @classmethod def from_id(cls, msg_id, user_id='me'): |
