Advertisement
furas

Python - IMAPClient - GMail

May 28th, 2018 (edited)
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. # author: Bartlomiej "furas" Burek (https://blog.furas.pl)
  2. # 2018.05.28
  3.  
  4. # 2020: currenlty to access GMail programs need special login/password generated on GMail,
  5. #       it will not works with login/password used normally in web browser
  6.  
  7. import imapclient
  8. import pyzmail
  9.  
  10. imap = imapclient.IMAPClient('imap.gmail.com', use_uid=True)
  11. imap.login('your-login', 'your-password')
  12.  
  13. #imap.select_folder('CRYPTO/trade', readonly=True)
  14. imap.select_folder('Inbox', readonly=True) # default folder with new messages
  15.  
  16. unseen = imap.search(b'UNSEEN')
  17.  
  18. for uid in unseen:
  19.     print('uid:', uid)
  20.    
  21.     msg = imap.fetch([uid], [b'BODY[]', b'FLAGS'])
  22.  
  23.     trade = None
  24.  
  25.     message = pyzmail.PyzMessage.factory(msg[uid][b'BODY[]'])
  26.     subject = message.get_subject()
  27.    
  28.     if 'strategy says sell now' in subject:
  29.         print('sell signal found')
  30.         print(subject)
  31.         trade = 'sell'
  32.     elif 'strategy says buy now' in subject:
  33.         print('buy signal found')
  34.         print(subject)
  35.         trade = 'buy'
  36.     else:
  37.         print('failed')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement