I made a script to check if there are new emails in my inbox, but it returns the emails (Gmail) from the Main, Social and Promotions box, but I just want to read the one from the Main box.
Its an script for my IA
# Call the Gmail API to fetch INBOX
results = service.users().messages().list(userId='me',labelIds = ['INBOX', 'UNREAD']).execute()
messages = results.get('messages', [])
if not messages:
frase = 'Sem novas mensagens na caixa de email'
a = Pesquise(frase)
a.fala(frase)
else:
for message in messages:
msg = service.users().messages().get(userId='me', id=message['id']).execute()
payld = msg['payload'] # get payload of the message
headr = payld['headers'] # get header of the payload
for one in headr: # getting the Subject
if one['name'] == 'Subject':
msg_subject = remover_acentos(one['value'])
else:
pass
frase = 'Hugo, novo email na caixa de entrada, ' + msg_subject
a = Pesquise(frase)
a.fala(frase)
sleep(600)
except Exception as err:
print err
I just want the script to read the Main box, not the Main, Social, and Promotions.