aenaveen

Paytm printer

Nov 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. import email
  2. import imaplib
  3. import quopri
  4. from time import sleep
  5. import datetime
  6. from email.header import decode_header
  7. from escpos.printer import Usb #ESCPOS Python
  8. p = Usb(0x0456,0x808,0,0x81,0x03) #do lsusb for these argument values of a particular p.texter.
  9.  
  10. try:
  11. username = 'surakshapaytm@gmail.com'
  12. password = 'thindlu@paytm'
  13.  
  14. mail = imaplib.IMAP4_SSL("imap.gmail.com") #https://www.google.com/settings/security/lesssecureapps5
  15. mail.login(username,password)
  16. mail.select('Paytm')
  17. now = datetime.datetime.now()
  18. tyear = str(now.year)
  19. p.text("\x1b!1\nPRINTER RESTARTED\n")
  20. p.text("\nSURAKSHA FUEL STATION\n")
  21. except Exception:
  22. p.text("\x1b!1\x1bE1 * * * * * * * * * *\nERROR \x1b-2Internet \x1b-0ERROR\n Please Call Naveen\n* * * * * * * * * *\n\x1b@\n")
  23.  
  24.  
  25. while True :
  26. sleep(1)
  27. try:
  28. mail.select('Paytm')
  29. result, data = mail.uid('search',None,"ALL")
  30. inbox_item_list = data[0].split()
  31.  
  32. for item in inbox_item_list:
  33. result2, email_data = mail.uid('fetch',item,('RFC822'))
  34. raw_email = email_data[0][1]
  35. #paytm----
  36. #email_message = email.message_from_string(raw_email.decode("utf-8"))
  37. #esubject = email_message['Subject']
  38. #phonepe----
  39. try:
  40.  
  41. email_message = email.message_from_bytes(raw_email)
  42. phonepecheck = email_message['From']
  43. if email_message['From'] == '"PhonePe" <noreply@phonepe.com>' :
  44. message = email_message.get_payload()
  45. textmessage = quopri.decodestring(message)
  46. esubject = email_message['Subject']
  47. desub = decode_header(esubject)
  48. esubject = desub[0][0]
  49. esubject = str(esubject)
  50.  
  51. findex = esubject.find("Received")
  52. findexend = esubject.find("from")
  53. amountpaid = esubject[findex+22:findexend-1]
  54.  
  55. payername= esubject[findexend+5:]
  56. textmessage = str(message)
  57. tfindex = textmessage.find(tyear)
  58. timepaid = textmessage[tfindex-17:tfindex+4]
  59.  
  60. p.text("\x1b!1PhonePe Received\n")
  61. p.text("\x1b!1\n\nAmount:Rs. "+amountpaid)
  62. p.text(timepaid)
  63. p.text("\x1b!1\]n\n\nSURAKSHA FUEL STATION\n")
  64. mail.uid('STORE',item, '+FLAGS', '(\\Deleted)')
  65. else:
  66. dec_email = raw_email.decode("utf-8")
  67. message = email.message_from_string(dec_email)
  68. esubject = email_message['Subject']
  69.  
  70. findex = esubject.find("paid by")
  71. amountpaid = esubject[:findex]
  72. mobnum = esubject[findex+8:findex+18]
  73.  
  74. findex = esubject.find("at")
  75. timepaid = esubject[findex+3:]
  76.  
  77. findex = dec_email.find("Transaction Count")+17
  78. trxncount = dec_email[findex:findex+4]
  79.  
  80. p.text("\x1b!1\n PAYTM Count: "+ trxncount+'\n'+mobnum+'\n')
  81. p.text("\x1b!1\n Amount: "+amountpaid+"\n"+timepaid+"\n\n")
  82. p.text("\x1b!1\n\nSURAKSHA FUEL STATION\n")
  83. #message.get_payload()
  84. mail.uid('STORE',item, '+FLAGS', '(\\Deleted)')
  85. except Exception:
  86. p.text("Different EMAIL Please Call NAVEEN"+esubject)
  87. except Exception:
  88. p.text('Sorry email ERROR')
  89. mail.login(username,password)
Add Comment
Please, Sign In to add comment