Guest User

Untitled

a guest
Jun 12th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import imaplib
  4. import datetime
  5.  
  6. from tumblr import Api
  7. import sys
  8.  
  9. BLOG='perolasdoaniceto.tumblr.com'
  10. USER='myusername'
  11. PASSWORD='mypassword'
  12.  
  13. api = Api(BLOG,USER,PASSWORD)
  14.  
  15. M=imaplib.IMAP4_SSL('imap.gmail.com', 993)
  16. M.login('myemail','mypass')
  17. status, count = M.select('Inbox')
  18.  
  19. since = datetime.datetime.now() - datetime.timedelta(hours=1)
  20. since = since.strftime("%d-%b-%Y")
  21. typ, dat = M.search(None, "SINCE", since, "FROM", "Aniceto")
  22. msgs = map(int, dat[0].split())
  23.  
  24.  
  25.  
  26. for msg in msgs:
  27. status, data = M.fetch(msg, '(UID BODY[HEADER.FIELDS (FROM SUBJECT DATE)])')
  28. if "Aniceto" in data[0][1]:
  29. status, body = M.fetch(msg, '(UID BODY[TEXT])')
  30. txt = body[0][1].decode("quopri")
  31.  
  32. parts = txt.split(74*"=")
  33. sign = parts[-1].split(14 * "-")[0].replace("<br>"," ").replace("\r\n"," ").replace("<div>","").replace("</div>","")
  34. while " " in sign:
  35. sign = sign.replace(" "," ")
  36. try:
  37. post = api.write_quote(sign)
  38. except Exception, e:
  39. print e
  40. M.close()
  41. M.logout()
Add Comment
Please, Sign In to add comment