Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import email
- import imaplib
- import quopri
- from time import sleep
- import datetime
- from email.header import decode_header
- from escpos.printer import Usb #ESCPOS Python
- p = Usb(0x0456,0x808,0,0x81,0x03) #do lsusb for these argument values of a particular p.texter.
- try:
- username = 'surakshapaytm@gmail.com'
- password = 'thindlu@paytm'
- mail = imaplib.IMAP4_SSL("imap.gmail.com") #https://www.google.com/settings/security/lesssecureapps5
- mail.login(username,password)
- mail.select('Paytm')
- now = datetime.datetime.now()
- tyear = str(now.year)
- p.text("\x1b!1\nPRINTER RESTARTED\n")
- p.text("\nSURAKSHA FUEL STATION\n")
- except Exception:
- p.text("\x1b!1\x1bE1 * * * * * * * * * *\nERROR \x1b-2Internet \x1b-0ERROR\n Please Call Naveen\n* * * * * * * * * *\n\x1b@\n")
- while True :
- sleep(1)
- try:
- mail.select('Paytm')
- result, data = mail.uid('search',None,"ALL")
- inbox_item_list = data[0].split()
- for item in inbox_item_list:
- result2, email_data = mail.uid('fetch',item,('RFC822'))
- raw_email = email_data[0][1]
- #paytm----
- #email_message = email.message_from_string(raw_email.decode("utf-8"))
- #esubject = email_message['Subject']
- #phonepe----
- try:
- email_message = email.message_from_bytes(raw_email)
- phonepecheck = email_message['From']
- if email_message['From'] == '"PhonePe" <noreply@phonepe.com>' :
- message = email_message.get_payload()
- textmessage = quopri.decodestring(message)
- esubject = email_message['Subject']
- desub = decode_header(esubject)
- esubject = desub[0][0]
- esubject = str(esubject)
- findex = esubject.find("Received")
- findexend = esubject.find("from")
- amountpaid = esubject[findex+22:findexend-1]
- payername= esubject[findexend+5:]
- textmessage = str(message)
- tfindex = textmessage.find(tyear)
- timepaid = textmessage[tfindex-17:tfindex+4]
- p.text("\x1b!1PhonePe Received\n")
- p.text("\x1b!1\n\nAmount:Rs. "+amountpaid)
- p.text(timepaid)
- p.text("\x1b!1\]n\n\nSURAKSHA FUEL STATION\n")
- mail.uid('STORE',item, '+FLAGS', '(\\Deleted)')
- else:
- dec_email = raw_email.decode("utf-8")
- message = email.message_from_string(dec_email)
- esubject = email_message['Subject']
- findex = esubject.find("paid by")
- amountpaid = esubject[:findex]
- mobnum = esubject[findex+8:findex+18]
- findex = esubject.find("at")
- timepaid = esubject[findex+3:]
- findex = dec_email.find("Transaction Count")+17
- trxncount = dec_email[findex:findex+4]
- p.text("\x1b!1\n PAYTM Count: "+ trxncount+'\n'+mobnum+'\n')
- p.text("\x1b!1\n Amount: "+amountpaid+"\n"+timepaid+"\n\n")
- p.text("\x1b!1\n\nSURAKSHA FUEL STATION\n")
- #message.get_payload()
- mail.uid('STORE',item, '+FLAGS', '(\\Deleted)')
- except Exception:
- p.text("Different EMAIL Please Call NAVEEN"+esubject)
- except Exception:
- p.text('Sorry email ERROR')
- mail.login(username,password)
Add Comment
Please, Sign In to add comment