aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/download_emails.py (renamed from python/test_oauth.py)13
1 files changed, 10 insertions, 3 deletions
diff --git a/python/test_oauth.py b/python/download_emails.py
index 41c1931a..e8c228cd 100644
--- a/python/test_oauth.py
+++ b/python/download_emails.py
@@ -9,6 +9,7 @@ from oauth2client import client
from oauth2client import tools
import json
import base64
+import pdb
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
@@ -73,6 +74,7 @@ def ListMessagesWithLabels(service, user_id, label_ids=[]):
return messages
except errors.HttpError as error:
print(json.loads(error.content.decode('utf-8'))['error']['message'])
+
def getListLabels(service, user_id):
try:
response = service.users().labels().list(userId=user_id).execute()
@@ -89,7 +91,9 @@ def get_msg(service, user_id, msg_id):
print(json.loads(error.content.decode('utf-8'))['error']['message'])
def msg_content(msg):
- return base64.b64decode(msg['payload']['body']['data']).decode('utf-8')
+ subject = [x['value'] for x in msg['payload']['headers'] if x['name']=='Subject'][0]
+ content = base64.b64decode(msg['payload']['body']['data']).decode('utf-8')
+ return subject, content
def main():
"""Shows basic usage of the Gmail API.
@@ -102,7 +106,10 @@ def main():
labelsdict = getListLabels(service, 'me')
r = []
for msg in ListMessagesWithLabels(service, 'me', labelsdict['swaptions']):
- print(msg_content(get_msg(service, 'me', msg['id'])))
+ 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 __name__ == '__main__':
- messages = main()
+ main()