def load_flashes(): say("Loading latest flashes...") for accountPair in configuration.get_accounts(): say("Loading flashes from Twitter account " + accountPair[0] + " (" + accountPair[1] + ")") latest_tweets = twitter.get_latest_statuses(accountPair[0][1:]) for tweet in latest_tweets: url = None if "entities" in tweet: if "urls" in tweet['entities']: if len(tweet['entities']['urls']) > 0: url = tweet['entities']["urls"][-1]['expanded_url'] push_flash( generate_flash(tweet["text"], url, accountPair[1], tweet["id"], tweet["created_at"], accountPair[2]) ) say("Loaded " + str(len(latest_tweets)) + " flashes from " + accountPair[0]) ok("Loaded " + str(len(latest_flashes)) + " flashes")
def get(self): try: req_resp = stats.request(str(get_ip(self.request))) say("Received API request (" + req_resp + ")") except: error("Errored while handling request IP -- still served...") self.set_header("Content-Type", "application/json") latest = -1 try: latest = int(self.get_argument('latest')) except: pass # no latest flash specified data = { "server": "LibreNews Central", "channels": [k[2] for k in configuration.get_accounts()], "latest": [ flash for flash in flashes.get_latest_flashes(25) if int(flash['id']) > int(latest) ] } self.write( unicode(json.dumps(data, sort_keys=True, separators=(',', ':'))))
def streamer_entrypoint(): twitter_stream = tweepy.Stream(twitter.auth, AccountListener()) twitter_stream.filter(follow=[str(twitter.get_id(k[0])) for k in configuration.get_accounts()], is_async=False)