def getData(): account = gmaillib.account(config.gmail['u'], config.gmail['p']) msgs = account.inbox(start=0,amount=10) transactions = [] # print msgs for msg in msgs: try: if "*****@*****.**" not in msg.sender_addr: continue except: continue debOrCred = None if "recent withdrawal" in msg.subject and "Transaction type: DEBIT POSTED" in msg.body: debOrCred = "debit" elif "direct deposit" in msg.subject and "Transaction type: ACH CREDIT" in msg.body: debOrCred = "credit" else: continue amounts = getAmounts(msg.body) date = parse(msg.date).replace(tzinfo=None) today = datetime.datetime.now() yesterday = (today-date).days == 0 if len(amounts) < 1: continue if not yesterday: continue for amount in amounts: transactions.append( {"type": debOrCred, "amount": amount, "time": date} ) output, outputDetail = "", "" if len(transactions) > 0: totDebits = 0.0 totCredits = 0.0 outputDetail += "Transaction details from yesterday (%s):" % (transactions[0]["time"].strftime("%m/%d/%y")) outputDetail += "<ul>" for trans in transactions: if trans["type"] == "debit": totDebits += trans["amount"] elif trans["type"] == "credit": totCredits += trans["amount"] outputDetail += "<li><b>%s</b> [%s]: %.2f</li>" % (trans["type"][:3].upper(), trans["time"].strftime("%I:%M%p"), trans["amount"]) outputDetail += "</ul>" output += "Yesterday, you " if totDebits > 0 and totCredits > 0: output += "spent <font color='red'>$%.2f</font> and gained <font color='green'>$%.2f</font>." % (totDebits, totCredits) elif totDebits > 0: output += "<font color='red'>spent $%.2f.</font>" % totDebits elif totCredits > 0: output += "<font color='green'>gained $%.2f.</font>" % totCredits if totDebits > 50: output += "<br><b><font color='red'>Damn! You spent more than $50 yesterday!</font></b>" return output, outputDetail
def on_ok(self): # try to create an instance of the mail class # based on the users login credentials. try: # pass account credentials, a link to the parent app # and a queue object attached to the parent application # for interprocess communication. self.parentApp.mail = account(self.username.value, self.password.value, parent=self.parentApp, queue=self.parentApp.queue) except Exception as e: npyscreen.notify_confirm(e, title="Error", form_color='STANDOUT', wrap=True, editw=1) return # notify the user that the login worked npyscreen.notify_confirm("Login successful", title="Success", form_color='STANDOUT', wrap=True, editw=1) # get inbox messages self.parentApp.mail.inbox_messages = self.parentApp.mail.inbox() self.parentApp.mail.inbox_messages.reverse() # assemble header information for all messages in the # inbox_messages list self.parentApp.mail.email_hdr_lst = [] for message in self.parentApp.mail.inbox_messages: #import pdb #pdb.set_trace() fmt_msg_hdr = "{0:<{width}.{width}} {1:<17.17} {2:<}".format( message.sender_addr.split(' <>')[0], message.date, message.subject, width=20) self.parentApp.mail.email_hdr_lst.append(fmt_msg_hdr) # take them back to the main men self.parentApp.switchForm('MAIN')
subject = email.subject if not subject: continue if "Sorry, we had to cancel." in subject: content = str(email.parsed_email) order_number = content.split( '</a>. There was a technical issue that prevented us from fulfilling your order.' )[0][-13:] canceled_orders.append(order_number) return canceled_orders if __name__ == '__main__': error_orders = [] g_account = None g_account = account(username, password) emails = g_account.inbox(start=0, amount=1000, date='11/15/2017') shipped_item_counter, shipped_order_counter = get_trackings(emails) canceled_orders = get_canceled_orders(emails) item_counter, order_counter = get_order_confirmations( emails, canceled_orders) for item in items: print item print 'qty: ', item_counter[item]['qty'] print 'shipped qty: ', shipped_item_counter[item]['qty'] print shipped_item_counter[item]['trackings'] for order_number in shipped_order_counter: if order_number not in order_counter: error_orders.append(order_number)
import gmaillib f=open('subjects.txt', 'w') account=gmaillib.account('username', 'password') emails = account.inbox(start=0, amount=5000) for email in emails: if email.subject is not None: f.write(email.subject + '\n') f.close()
def receiveSources(uname='', mtype='unread', mailbox='Inbox'): userlist = [[], ] ms.listuser(uname, userlist) for user in userlist[0]: user_account = account(user['uname'], des.decode(user['dpasswd'])) if mtype == 'unread': mailidlist = user_account.unread(mailbox=mailbox, onlyidlist=True) elif mtype == 'all': mailidlist = user_account.get_all_messages(mailbox=mailbox, onlyidlist=True) else: mailidlist = [] ms.maildb.fetchlog.save({'event': 'fetchstart', 'uname': user['uname'], 'maillist': mailidlist, 'datetime': datetime.now()}) mailbox = mailbox.split('/')[-1].replace('&', '+').decode('utf-7') for mailid in mailidlist: try: filename = "%s.eml" %(mailid) filepath = os.path.join(mailboxdir, user['alias'], mailbox) if not os.path.exists(filepath): os.makedirs(filepath) filename = os.path.join(filepath, filename) if os.path.exists(filename): continue source = user_account.recieve(mailid) log.debug("get source: %s {%s}", mailid, len(source)) filename = os.path.join(filepath, filename) file = open(filename, 'w') file.write(source) file.close() if mailbox == 'Inbox': save2edo(user['alias'], file.name) where = {'uname': user['uname'], 'mailbox': mailbox, 'sourcename': filename} if not ms.mails.find(where).count(): ms.mails.save({'sourcename': filename, 'uname': user['uname'], 'mailbox': mailbox, 'source': Binary(source, 128)}) ms.maildb.fetchlog.save({'event': 'fetchsuccess', 'uname': user['uname'], 'mailbox': mailbox, 'mailid': mailid, 'datetime': datetime.now()}) except: errinfo = "".join(traceback.format_exception(*sys.exc_info())) log.error('get_source [%s] error: %s', mailid, errinfo.decode('utf-8')) ms.maildb.fetchlog.save({'event': 'fetcherror', 'uname': user['uname'], 'mailbox': mailbox, 'mailid': mailid, 'error': errinfo, 'datetime': datetime.now()}) continue return len(mailidlist)
def readSerial(): # Wait for Arduino to report it is ready before starting as windows will reset the arduino line = "" while True: for c in com.read(): line += c if c == '\n': return def setLEDOn(state): if state: com.write("on;") else: com.write("off;") # Open serial coms com = serial.Serial(2, 9600) # Wait for arduino to be ready readSerial() gmail = gmaillib.account("andycampbell92", "S1E$#YvNTI2z") while True: unread = gmail.unread() if len(unread) > 0: setLEDOn(True) print "unread" else: print "read" setLEDOn(False) time.sleep(5)
import gmaillib f = open('subjects.txt', 'w') account = gmaillib.account('username', 'password') emails = account.inbox(start=0, amount=5000) for email in emails: if email.subject is not None: f.write(email.subject + '\n') f.close()