def store_pending_tweet(self, trackID, trackYouTubeID, playCount, pos): ## in this example, we're going to store the track primary key, the associated youtube video id, the # of times played, and the rank. pt = PendingTweet(trackPk=trackID, youtubeID=trackYouTubeID, playCount=playCount, rank=pos) pt.put() logger.info("Adding a PendingTweet (%s) " % pt) return 1
def store_pending_tweets(self, query_results): logger.debug('attempting to store pending tweets') trackIDcache = [] # keep a cache to ensure that we aren't adding the same PRIMARY_KEY twice. artifact of my analytics data. """ now we store our pending tweets """ if len(query_results.get('rows', [])) > 0: db.delete(PendingTweet.all()) # clear all the pending tweets logger.debug("cleared all pending tweets") pos = 1 for row in query_results.get('rows'): logger.debug( '\t'.join(row) ) firstPart = row[0].index("_") # eventLabel, the first column, looks like "12726_NngHqOYtMoo" trackInfo = [row[0][0:firstPart], row[0][firstPart+1:]] logger.debug("track info is %s " % trackInfo) trackID = trackInfo[0] trackYouTubeID = trackInfo[1] playCount = long(row[1]) if trackID not in trackIDcache and trackYouTubeID != 'NoVideoFound': pos += self.store_pending_tweet(trackID, trackYouTubeID, playCount, pos) trackIDcache.append(trackID)
def store_pending_tweets(self, query_results): logger.debug('attempting to store pending tweets') trackIDcache = [ ] # keep a cache to ensure that we aren't adding the same PRIMARY_KEY twice. artifact of my analytics data. """ now we store our pending tweets """ if len(query_results.get('rows', [])) > 0: db.delete(PendingTweet.all()) # clear all the pending tweets logger.debug("cleared all pending tweets") pos = 1 for row in query_results.get('rows'): logger.debug('\t'.join(row)) firstPart = row[0].index( "_" ) # eventLabel, the first column, looks like "12726_NngHqOYtMoo" trackInfo = [row[0][0:firstPart], row[0][firstPart + 1:]] logger.debug("track info is %s " % trackInfo) trackID = trackInfo[0] trackYouTubeID = trackInfo[1] playCount = long(row[1]) if trackID not in trackIDcache and trackYouTubeID != 'NoVideoFound': pos += self.store_pending_tweet(trackID, trackYouTubeID, playCount, pos) trackIDcache.append(trackID)