SHARE
TWEET

Python - imapclient - GMail

furas May 28th, 2018 363 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! python3
  2.  
  3. import imapclient
  4. import pyzmail
  5.  
  6. imap = imapclient.IMAPClient('imap.gmail.com', use_uid=True)
  7. imap.login('your-login', 'your-password')
  8.  
  9. #imap.select_folder('CRYPTO/trade', readonly=True)
  10. imap.select_folder('Inbox', readonly=True) # default folder with new messages
  11.  
  12. unseen = imap.search(b'UNSEEN')
  13.  
  14. for uid in unseen:
  15.     print('uid:', uid)
  16.    
  17.     msg = imap.fetch([uid], [b'BODY[]', b'FLAGS'])
  18.  
  19.     trade = None
  20.  
  21.     message = pyzmail.PyzMessage.factory(msg[uid][b'BODY[]'])
  22.     subject = message.get_subject()
  23.    
  24.     if 'strategy says sell now' in subject:
  25.         print('sell signal found')
  26.         print(subject)
  27.         trade = 'sell'
  28.     elif 'strategy says buy now' in subject:
  29.         print('buy signal found')
  30.         print(subject)
  31.         trade = 'buy'
  32.     else:
  33.         print('failed')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top