forked from gopavasanth/Automate-Status-Updates
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesages.py
More file actions
73 lines (57 loc) · 2.27 KB
/
Copy pathmesages.py
File metadata and controls
73 lines (57 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Gopavasanth
# Date : 05/05/2018
from __future__ import print_function
import httplib2
import os
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
import auth
SCOPES = 'https://mail.google.com/'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Gmail API Python Quickstart'
authInst = auth.auth(SCOPES,CLIENT_SECRET_FILE,APPLICATION_NAME)
credentials = authInst.get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('gmail', 'v1', http=http)
def list_messages_matching_query(service, user_id="me", query='[foss-2017] Status Update [27-06-2018]'):
"""List all Messages of the user's mailbox matching the query.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. The special value "me"
can be used to indicate the authenticated user.
query: String used to filter messages returned.
Eg.- 'from:user@some_domain.com' for Messages from a particular sender.
Returns:
List of Messages that match the criteria of the query. Note that the
returned list contains Message IDs, you must use get with the
appropriate ID to get the details of a Message.
"""
try:
response = service.users().messages().list(userId=user_id,
q=query).execute()
messages = []
if 'messages' in response:
messages.extend(response['messages'])
while 'nextPageToken' in response:
page_token = response['nextPageToken']
response = service.users().messages().list(
userId=user_id, q=query, pageToken=page_token).execute()
messages.extend(response['messages'])
print (messages)
return messages
except errors.HttpError as error:
print('An error occurred: %s' % error)
from datetime import date
today = str(date.today())
print("Today Date :" + today)
today = '[%s]' % date.today().strftime('%d-%m-%Y')
print (today)
list_messages_matching_query(service, user_id="me", query='[foss-2017] Status Update ' + today)
#return mssg