aboutsummaryrefslogtreecommitdiffstats
path: root/python/download_emails.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/download_emails.py')
-rw-r--r--python/download_emails.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/python/download_emails.py b/python/download_emails.py
index f4b874ea..1ab7c0a5 100644
--- a/python/download_emails.py
+++ b/python/download_emails.py
@@ -94,8 +94,7 @@ 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')
+ _labels = labels_dict(EmailMessage._service, 'me')
def msgdict(self):
return {'raw': base64.urlsafe_b64encode(self.as_bytes()).decode()}
@@ -112,12 +111,12 @@ class GmailMessage(EmailMessage):
@staticmethod
def list_msg_ids(label, start_history_id=None):
if start_history_id is not None:
- return ListHistory(GmailMessage._service,
+ return ListHistory(EmailMessage._service,
'me',
label_id=GmailMessage._labels[label],
start_history_id=start_history_id)
else:
- return ListMessagesWithLabels(GmailMessage._service,
+ return ListMessagesWithLabels(EmailMessage._service,
'me',
label_ids=[GmailMessage._labels[label]])
@@ -136,14 +135,13 @@ class GmailMessage(EmailMessage):
def save_emails(update=True):
"""Download new emails that were labeled swaptions."""
-
- labelsdict = labels_dict(GmailMessage._service, 'me')
DATA_DIR = Path(os.getenv("DATA_DIR"))
if update:
try:
last_history_id = int((DATA_DIR / ".lastHistoryId").read_text())
except FileNotFoundError:
+ logging.error("can't find .lastHistoryId file")
sys.exit()
existing_msgs = []
else: