本文整理汇总了Python中Debug.writeOut方法的典型用法代码示例。如果您正苦于以下问题:Python Debug.writeOut方法的具体用法?Python Debug.writeOut怎么用?Python Debug.writeOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Debug
的用法示例。
在下文中一共展示了Debug.writeOut方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: postDailySummary
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import writeOut [as 别名]
def postDailySummary(self):
'''Posts a daily summary to Twitter'''
# Get current minutes from system time
currentTime = datetime.now()
# create time difference to be used to work out time period
timeDiff = timedelta(days=1)
# Get current minutes
currentHour = currentTime.strftime("%H")
# Check if the hours of the time is 00 which means midnight and the current day
# has changed
if(currentHour == "00" and (self.LAST_DAY_POST == "" or currentTime.strftime("%d") != self.LAST_DAY_POST)):
Debug.writeOut("Daily condition met (hour of day:" + currentHour + " == 00 && day:" + currentTime.strftime("%d") + " == " + self.LAST_DAY_POST + "). Posting to Twitter")
# Create SQL to get data for tweet
sql = " SELECT COALESCE(ROUND(AVG(energy), 2), 0), COALESCE(MAX(energy), 0), COALESCE(ROUND(AVG(temperature), 1), 0) FROM historical_data WHERE date_time >= ADDDATE(NOW(), INTERVAL -1 DAY)"
self.LOGGER.debug(sql)
# Get statistics from DB
stats = MySQL.executeOneUpdate(sql, None)
# Create tweet
message = (currentTime - timeDiff).strftime("%d-%b-%Y") + " Summary: " + str(stats[0]) +\
"w was used. " +\
"Energy usage peaked at " + str(stats[1]) + "w. " +\
"The average temperature was " + str(stats[2]) + "c."
# Save new day of tweet
self.LAST_DAY_POST = currentTime.strftime("%d")
# Check if tweet should be a Direct Message or just a tweet
if self.CONFIG.getBooleanConfig("Twitter", "directMessagePost"):
self.postDirectMessage(self.CONFIG.getBooleanConfig("Twitter", "directMessageUser"), message)
else:
# Post message to twitter
self.tweet(message)
示例2: postHourlySummary
# 需要导入模块: import Debug [as 别名]
# 或者: from Debug import writeOut [as 别名]
def postHourlySummary(self):
'''Posts an hourly summary to Twitter'''
# Get current system time
currentTime = datetime.now()
# create time difference to be used to work out time period
timeDiff = timedelta(hours=1)
# Get current hour
currentHour = currentTime.strftime("%H")
# If current hour does not match last post hour then it's been a new hour since last post
if(currentHour != self.LAST_HOURLY_POST):
Debug.writeOut("Hourly condtion met (" + currentHour + " != " + self.LAST_HOURLY_POST + "). Posting to Twitter")
# Create SQL to get data for tweet
sql = "SELECT COALESCE(ROUND(AVG(energy), 2), 0), " +\
"COALESCE(MAX(energy), 0), COALESCE(ROUND(AVG(temperature), 1), 0) " +\
"FROM historical_data WHERE date_time >= ADDDATE(NOW(), INTERVAL -1 HOUR)"
self.LOGGER.debug(sql)
# Get statistics from DB
stats = MySQL.executeOneUpdate(sql, None)
# Create tweet
message = (currentTime - timeDiff).strftime("%H:%M") + "-" + currentTime.strftime("%H:%M") +\
" Summary: " + str(stats[0]) + "w was used." +\
" Energy usage peaked at " + str(stats[1]) + "w" +\
". The average temperature was " + str(stats[2]) + "c."
# Check if tweet should be a Direct Message or just a tweet
if self.CONFIG.getBooleanConfig("Twitter", "directMessagePost"):
self.postDirectMessage(self.CONFIG.getBooleanConfig("Twitter", "directMessageUser"), message)
else:
# Post message to twitter
self.tweet(message)
# Set last hourly post to current hour
self.LAST_HOURLY_POST = currentHour