コード例 #1
0
def save_tweet(lastUpdate):
    # set up the DB
    db = configs.get_redis_conn()

    # save the tweet!
    db.set(("tweets:%s" % lastUpdate["id"]), json.dumps(lastUpdate))
    db.lpush("tweets:tweet_ids", lastUpdate["id"])
    return "Tweet \"%s\"saved at %s" % (lastUpdate["text"], datetime.datetime.now())
コード例 #2
0
def grab_all_the_things():
    # oh hai redis
    db = configs.get_redis_conn()

    print ("--------------------------------------")

    # teh twitter
    updates = grab_twitter_updates()
    lastUpdate = updates[0]
    timestampstring = lastUpdate["created_at"] + ' UTC'
    timestamp = time.mktime(time.strptime(timestampstring,  '%a  %b %d %H:%M:%S +0000 %Y %Z'))
    lastUpdate["timestamp"] = timestamp

    print ("Last update created_at: %s" % lastUpdate["created_at"])
    print ("Last update timestamp: %s" % lastUpdate["timestamp"])
    print ("Last update id: %s" % lastUpdate["id"])
    print ("Last update text: %s" % lastUpdate["text"])

    '''
    This should look like:

    Last update created_at: Sat Nov 26 16:30:03 +0000 2011
    Last update timestamp: 1322343003.0
    Last update id: 140467359902203906
    Last update text: optioning
    '''

    datters = db.get("tweets:%s" % lastUpdate["id"])
    if datters:
        # eh, old tweet
        print("Same tweet. Carry on.")
    else:
        # it is a new tweet!
        print("NEW TWEET!")

        saved = save_tweet(lastUpdate)
        print 'saved!'

        tweeted = tweet_tweet(lastUpdate)
        print 'tweeted!'

        redis_cleanup.trim_redis_keys()
        print 'cleaned!'

        return tweeted, saved
コード例 #3
0
def trim_redis_keys():
    db = configs.get_redis_conn()
    keys = db.keys('*')

    print "I hear tell it's time to clean out some keys"

    print "key length: %s" % len(keys)

    if (len(keys) > 99):
        keys.sort()
        keys.reverse()
        keys_to_delete = keys[99:len(keys)]
        for key in keys_to_delete:
            if key is not 'checks':
                print ('deleting key: %s' % key)
                db.delete(key)
    else:
        print "all good here. as you were."