def updateIcon(state): # global db from libs.services._twitter import Tweet tweet = Tweet() # if db.isLocked(): # tweet.setImage('http://door.just1.name/wp-content/themes/icon-locked.png') # tweet.setImage('/home/rossetti/door/icon-locked.jpg') # else: # tweet.setImage('http://door.just1.name/wp-content/themes/icon-unlocked.png') # tweet.setImage('/home/rossetti/door/icon-unlocked.jpg') tweet.setImage("/home/rossetti/door/icon-%s.jpg" % state.lower())
def stateChanged(state): # update the twitter icon updateIcon(state) sys.stderr.write("Door state changed: %s" % state) # send a state changed message from libs.services._twitter import Tweet tweet = Tweet() msg = "d queenvictoria %s" % (state) tweet.setMessage(msg) tweet.send() # update the door last as it will die if the controller board is disconnected updateDoor(state)
def checkHealth(): from libs.services._health import Health health = Health() output = [] for k, v in health.data.items(): output.append("%s %s" % (k, v)) output = ', '.join(output) print "Sending %s" % output # send a state changed message from libs.services._twitter import Tweet tweet = Tweet() msg = "d queenvictoria %s" % (output) tweet.setMessage(msg) tweet.send()
def main(): global options, db options = libs.utils.load_options() db = dbConnector() print "OK" if len(sys.argv) > 1: if sys.argv[1] == '--test': sendToLogger() sys.exit() if sys.argv[1] == '--lock': updateDoor('locked') sys.exit() if sys.argv[1] == '--unlock': updateDoor('unlocked') sys.exit() if sys.argv[1] == '--state': print db.getState() sys.exit() if sys.argv[1] == '--sparks': sendSparklines() sendToServer() sys.exit() if sys.argv[1] == '--health': checkHealth() sys.exit() if sys.argv[1] == '--log': sendToLogger() sys.exit() if sys.argv[1] == '--tweet': sendTweets() sys.exit() if sys.argv[1] == '--test-tweet': from libs.services._twitter import Tweet tweet = Tweet() msg = "d queenvictoria %s" % (db.getState()) if len(sys.argv) == 3: msg = "%s %s" % (msg, sys.argv[2]) tweet.setMessage(msg) tweet.send() sys.exit() sendUpdates()
def sendTweets(): global options, db # search the db for the weeks happiest news # $UTC = getUTCByDateAndTimezone(date('Y-m-d H:i:s', strtotime('-7 days')), "Australia/Sydney"); # $SELECT = " # $S # FROM articles # LEFT JOIN ratings_1 ON articles.id = ratings_1.id # WHERE articles.date_utc > date('$UTC') # ORDER BY ratings_1.q4 DESC # LIMIT 1 # "; # $results3 = $db->query($SELECT); # the_date = datetime.today() - timedelta(days=7) # one_week_ago = getUTCDate(time.strftime('%Y-%m-%d %H:%M:%S', the_date.timetuple()), "Australia/Sydney") # query = 'SELECT articles.title, articles.link, articles.id FROM articles LEFT JOIN ratings_1 ON articles.id = ratings_1.id WHERE date(articles.date_utc) > "%s" ORDER BY ratings_1.q4 DESC LIMIT 1' % (one_week_ago) # from pysqlite2 import dbapi2 as sqlite # db = sqlite.connect('door_wordlist.db') # cursor = db.cursor() # cursor.execute(query) # item = cursor.fetchone() # d7_q4 = db.getStrongestResult(7, 4) d7_q4 = db.getStrongestMood(7, 'happy') # d7_q4 = db.getStrongestMoods(7, 'happy', 3) item = d7_q4 print item # if we've already announced the joyous news do nothing last_update = libs.utils.get_option('last_update') # last_update = '' print last_update if last_update == item[4]: print "Already sent" return else: print "New update %d" % item[4] # otherwise continue on and send updates from libs.services._twitter import Tweet tweet = Tweet() # update our followers first tweet.updateFollowing() # create a short url pointing to the original article url = tweet.ShortenUrl(item[1], 'trim').strip() print url # determine any hashtags to use title = item[0] max_length = 140 # trim the title if necessary if len(title) + len(url) >= max_length: print 'Trim required.' title = title[:max_length - len(url) - 1] msg = "%s %s" % (title, url) print "%s [%d]" % (msg, len(msg)) tweet.setMessage(msg) tweet.send() libs.utils.set_option('last_update', item[4])
def updateTwitterFollowing(): from libs.services._twitter import Tweet tweet = Tweet() print tweet.updateFollowing()