def produce_next_tweet(app_status): app_status = status.load() # Just get the latest tweets tweets = twitter.get_timeline_tweets(800) tweets = filter_tweets(tweets) tweets = filter(lambda t:not t['user']['screen_name'] == twitter_settings.screen_name, tweets) if len(tweets) <= 1: print('Could not generate tweet (not enough eligible tweets)') app_status['latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)' return recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True) best_tweet = create_markovated_tweet(tweets, 140, map(lambda t: t['text'].strip(), recent_tweets)) if best_tweet != None: html_ent = re.findall(regexp, best_tweet) for e in html_ent: h = HTMLParser.HTMLParser() unescaped = h.unescape(e) #finds the unescaped value of the html entity best_tweet = best_tweet.replace(e, unescaped) #replaces html entity with unescaped value twitter.post_tweet(best_tweet, None) encoded = unicode(best_tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_tweet'] = encoded; else: print('Could not generate tweet') app_status['latest_tweet'] = 'Could not generate tweet' status.save(app_status)
def produce_next_tweet(app_status): app_status = status.load() # Just get the latest tweets tweets = twitter.get_timeline_tweets(800) tweets = filter_tweets(tweets) tweets = filter(lambda t:not t['user']['screen_name'] == twitter_settings.screen_name, tweets) if len(tweets) <= 1: print('Could not generate tweet (not enough eligible tweets)') app_status['latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)' return recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True) best_tweet = create_markovated_tweet(tweets, 140, map(lambda t: t['text'].strip(), recent_tweets)) if best_tweet != None: twitter.post_tweet(best_tweet) encoded = unicode(best_tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_tweet'] = encoded; else: print('Could not generate tweet') app_status['latest_tweet'] = 'Could not generate tweet' status.save(app_status)
def produce_next_tweet(app_status): app_status = status.load() # Just get the latest tweets tweets = twitter.get_timeline_tweets(800) tweets = filter_tweets(tweets) tweets = filter( lambda t: not t['user']['screen_name'] == twitter_settings.screen_name, tweets) if len(tweets) <= 1: print('Could not generate tweet (not enough eligible tweets)') app_status[ 'latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)' return recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True) best_tweet = create_markovated_tweet( tweets, 140, map(lambda t: t['text'].strip(), recent_tweets)) if best_tweet != None: twitter.post_tweet(best_tweet) encoded = unicode(best_tweet).encode('utf-8') print(encoded + '(' + str(len(encoded)) + ')') app_status['latest_tweet'] = encoded else: print('Could not generate tweet') app_status['latest_tweet'] = 'Could not generate tweet' status.save(app_status)
def process_replies(): app_status = status.load() since_id = app_status.get('reply_since_id', -1) if since_id: mentions = twitter.get_mentions(since_id) else: mentions = twitter.get_mentions() print(str(len(mentions))+" mentions since "+str(since_id)) mentions.reverse() for mention in mentions: #twitter.follow_user(mentions[-1]['user']['screen_name']) reply_to_user(mention['user'], app_status, mention['id']) app_status['reply_since_id'] = mention['id'] app_status['latest_user_replied_to'] = mention['user']['screen_name'] # Save after each one so if we crash we don't resend replies status.save(app_status)
def process_replies(): app_status = status.load() since_id = app_status.get('reply_since_id', -1) if since_id: mentions = twitter.get_mentions(since_id) else: mentions = twitter.get_mentions() print(str(len(mentions)) + " mentions since " + str(since_id)) mentions.reverse() for mention in mentions: twitter.follow_user(mentions[-1]['user']['screen_name']) reply_to_user(mention['user'], app_status) app_status['reply_since_id'] = mention['id'] app_status['latest_user_replied_to'] = mention['user']['screen_name'] # Save after each one so if we crash we don't resend replies status.save(app_status)
import file_system_status as status s = {} s['reply_since_id'] = '123' status.save(s) s = status.load() assert s['reply_since_id'] == '123' status.clear() s = status.load() assert 'reply_since_id' not in s print("Tests passed")