subject = msg['Subject'][0:64] except: subject = "No Subject" try: dte = datetime.datetime.fromtimestamp( time.mktime( email.utils.parsedate( msg['Date']))) except: continue iso = dte.strftime("%Y-%m-%d") if iso in datekeys: dates[iso]['total'] += 1 else: dates[iso] = {'total': 1} datekeys.append(iso) if DEBUG: sys.stdout.write('%3.2f%% - %s\r' % ((count / length) * 100, "")) sys.stdout.flush() if DEBUG: print "100%" print "Databasing...." for date in dates.keys(): lifestreamutils.newstat(date, STATISTIC, dates[date]['total']) dbcxn.close()
toSleep = lifestream.niceTimeDelta(sleep['minutesToFallAsleep'] * 60) asleep = lifestream.niceTimeDelta(sleep['duration'] / 1000) title = "Took %s to fall asleep for %s (%d%% efficent sleep)." % ( toSleep, asleep, sleep['efficiency']) logger.info("Sleep: %s" % title) Lifestream.add_entry( type=type, id=id, title=title, source="fitbit", date=date, fulldata_json=sleep) lifestreamutils.newstat( sleep['startTime'], "sleep", sleep['minutesAsleep']) for badge in fbcxn.get_badges()['badges']: type = "badge" id = badge['badgeType'] + str(badge['value']) + badge['dateTime'] url = '' image = badge['image75px'] date = badge['dateTime'] logger.info("Badge: %s" % badge['image75px']) Lifestream.add_entry( type=type, id=id, title='', source="fitbit",