def get_analyses(ma_recherche: str, nbr_result: int): raw_tweet_list = twitter.twitter_api.recherche(ma_recherche, nbr_result) tweet_list = Tweet.from_raw_list(raw_tweet_list, ma_recherche) print(len(tweet_list)) documents = azure.azure_api.from_tweetlist_to_documents( frozenset(tweet_list)) azure_json = azure.azure_api.sentiments(documents) tweet_list = Tweet.from_azure_response(tweet_list, azure_json) return tweet_list
def get(self): try: tweet_frequency = Configuration.get_instance().tweet_frequency if randint(1, tweet_frequency) == 2: qry = Tweet.query(Tweet.sent == None).order(Tweet.priority, -Tweet.priority) found_tweets = qry.fetch(1) if found_tweets and len(found_tweets) > 0: found_tweet = found_tweets[0] post_tweet(found_tweet.message) found_tweet.sent = datetime.datetime.now() found_tweet.put() logging.info("Tweet posted") else: logging.info("No tweets to send") else: logging.info("Decided not to tweet, frequency " + str(tweet_frequency) + ".") self.response.status = 200 except Exception as e: self.response.status = 500 trace = traceback.format_exc() logging.error(e.message) logging.error(trace)
def get(self): try: tweet_frequency = Configuration.get_instance().tweet_frequency if randint(1, tweet_frequency) == 2: qry = Tweet.query(Tweet.sent == None).order( Tweet.priority, -Tweet.priority) found_tweets = qry.fetch(1) if found_tweets and len(found_tweets) > 0: found_tweet = found_tweets[0] post_tweet(found_tweet.message) found_tweet.sent = datetime.datetime.now() found_tweet.put() logging.info("Tweet posted") else: logging.info("No tweets to send") else: logging.info("Decided not to tweet, frequency " + str(tweet_frequency) + ".") self.response.status = 200 except Exception as e: self.response.status = 500 trace = traceback.format_exc() logging.error(e.message) logging.error(trace)
def post(self): tweet_id = int(self.request.POST['id']) found_tweet = Tweet.get_by_id(tweet_id) if found_tweet: found_tweet.key.delete() self.redirect('/admin/tweets')