FILE = 'getYesterdaysUsage' getUsage = False if not os.path.exists(FILE): open(FILE,'w').close() getUsage=True # getUsage if we have to create the file # get last time FILE was modified lastSuccess = time.ctime(os.path.getmtime(FILE)) dateLastSuccess = datetime.strptime(lastSuccess,'%a %b %d %H:%M:%S %Y') #If file was modified on a day that is not today, update usage stats if dateLastSuccess.day != datetime.now().day: getUsage = True if getUsage == True: t = TStat('thermostat-FD-BB-6F.chiefmarley.local') heatUsage = t.getHeatUsageYesterday() coolUsage = t.getCoolUsageYesterday() heatMinutes = heatUsage['hour'] * 60 + heatUsage['minute'] coolMinutes = coolUsage['hour'] * 60 + coolUsage['minute'] currentTime = int(round(time.time())) touch(FILE) conn = sqlite3.connect('/home/andy/djangoProjects/leeHouseSite/sqlite/db.sql3') c = conn.cursor() c.execute("insert into restInterface_hvac_runtime values (NULL," + str(currentTime) + "," + str(heatMinutes) +"," + str(coolMinutes) + ")") conn.commit()
getUsage = False if not os.path.exists(FILE): open(FILE, 'w').close() getUsage = True # getUsage if we have to create the file # get last time FILE was modified lastSuccess = time.ctime(os.path.getmtime(FILE)) dateLastSuccess = datetime.strptime(lastSuccess, '%a %b %d %H:%M:%S %Y') #If file was modified on a day that is not today, update usage stats if dateLastSuccess.day != datetime.now().day: getUsage = True if getUsage == True: t = TStat('thermostat-FD-BB-6F.chiefmarley.local') heatUsage = t.getHeatUsageYesterday() coolUsage = t.getCoolUsageYesterday() heatMinutes = heatUsage['hour'] * 60 + heatUsage['minute'] coolMinutes = coolUsage['hour'] * 60 + coolUsage['minute'] currentTime = int(round(time.time())) touch(FILE) conn = sqlite3.connect( '/home/andy/djangoProjects/leeHouseSite/sqlite/db.sql3') c = conn.cursor() c.execute("insert into restInterface_hvac_runtime values (NULL," + str(currentTime) + "," + str(heatMinutes) + "," + str(coolMinutes) + ")") conn.commit()