diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/collateral_calc.py | 2 | ||||
| -rw-r--r-- | python/gmail_helpers.py | 10 |
2 files changed, 9 insertions, 3 deletions
diff --git a/python/collateral_calc.py b/python/collateral_calc.py index d2283910..47a9bda8 100644 --- a/python/collateral_calc.py +++ b/python/collateral_calc.py @@ -9,7 +9,6 @@ from pathlib import Path from time import sleep from pandas.tseries.offsets import BDay from paramiko import Transport, SFTPClient, RSAKey -from download_emails import GmailMessage from sqlalchemy.exc import IntegrityError DAILY_DIR = Path(os.environ["DAILY_DIR"]) @@ -77,6 +76,7 @@ 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'): try: message = GmailMessage.from_id(msg['id']) diff --git a/python/gmail_helpers.py b/python/gmail_helpers.py index 67ca81ec..ff7c49bd 100644 --- a/python/gmail_helpers.py +++ b/python/gmail_helpers.py @@ -124,8 +124,14 @@ def labels_dict(service, user_id): print(json.loads(error.content.decode('utf-8'))['error']['message']) class GmailMessage(EmailMessage): - _service = get_gmail_service() - _labels = labels_dict(_service, 'me') + _service = None + _labels = None + + def __init__(self): + if GmailMessage._service is None: + GmailMessage._service = get_gmail_service() + if GmailMessage._labels is None: + GmailMessage._labels = labels_dict(self._service, 'me') def msgdict(self): return {'raw': base64.urlsafe_b64encode(self.as_bytes()).decode()} |
