def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) fav_per_tweet, rt_per_tweet = stats.get_averages(statuses) response = "Based on your last 200 tweets, you average %0.3f favorites and %0.3f retweets per tweet" % (fav_per_tweet, rt_per_tweet,) # Store data in tweets collection util.add_tweets(statuses, wilbur) return response
def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) common_hour, pm_or_am = stats.get_hour(statuses) response = "Based on your last 200 tweets, you are most active on twitter on the hour of " + str( common_hour) + " " + pm_or_am + " EST" # Store data in tweets collection util.add_tweets(statuses, wilbur) return response
def add_tracker(ticker): ticker = ticker.upper() fundamentals = {} connection = util.connect_to_postgres() cursor = connection.cursor() try: cursor.execute("CALL add_tracker(%s);", (ticker, )) except Exception as e: return {'error': str(e)} if not util.add_daily_price_data(ticker, session, connection, cursor) or not util.add_minute_price_data( ticker, session, connection, cursor): cursor.close() connection.close() return {'error': 'COULD NOT ADD PRICE DATA FOR' + ' ' + ticker} try: cursor.execute("SELECT * FROM Fundamentals WHERE ticker = %s", (ticker, )) except Exception as e: return {'error': str(e)} fundamentals = cursor.fetchone() util.add_tweets(ticker, fundamentals[1], TWEEPY_API, session, connection, cursor) util.add_news_articles(ticker, session, connection, cursor) col_ref = mongo_db['Live_Stock_Prices'] daily_prices = util.get_past_week_prices_mongo(ticker, session) if daily_prices: connection.commit() cursor.close() connection.close() new_tracker = { 'ticker': ticker, 'name': fundamentals[1], 'industry': fundamentals[2], 'sector': fundamentals[3], 'market_cap': fundamentals[4], 'description': fundamentals[5], 'daily_prices': daily_prices, 'minute_prices': [], 'prev_ema': [-1] * 391, 'ema_volume': [-1] * 391, 'minute_volume': [-1] * 391 } col_ref.insert_one(new_tracker) else: cursor.close() connection.close() return {'error': 'Failed to add {}!'.format(ticker)} return {'success': 'Successfully added {}!'.format(ticker)}
def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) # Part 1 = Get statistical data for reports fav_per_tweet, rt_per_tweet = stats.get_averages(statuses) # Round our numbers fav_per_tweet = round(fav_per_tweet, 3) rt_per_tweet = round(rt_per_tweet, 3) emoji = stats.get_emoji(statuses) hour = str(stats.get_hour(statuses)[0]) + " " + stats.get_hour(statuses)[1] word_count = stats.get_word_count(statuses) mention_count = stats.get_mention_count(statuses) sorted_words = sorted(word_count.iteritems(), key=operator.itemgetter(1), reverse=True)[:5] sorted_mention = sorted(mention_count.iteritems(), key=operator.itemgetter(1), reverse=True)[:5] most_used_words = [] for word in sorted_words: most_used_words.append(word[0]) most_mentioned = [] for mention in sorted_mention: most_mentioned.append(mention[0]) # Part 2 = Store data in reports collection data = { 'twitterHandle': author.screen_name, 'avgFavorites': fav_per_tweet, 'avgRetweets': rt_per_tweet, 'mostUsedEmoji': emoji, 'mostActiveHour': hour, 'mostUsedWords': most_used_words, 'mostMentioned': most_mentioned, 'updated': datetime.datetime.now().strftime("%m/%d %H:%M") } wilbur.reports.update({'twitterHandle': author.screen_name}, {"$set": data}, upsert=True) response = "View your report at http://wilbur.wilhelmwillie.com/report/" + author.screen_name # Part 3 = Store data in tweets collection util.add_tweets(statuses, wilbur) return response
def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) fav_per_tweet, rt_per_tweet = stats.get_averages(statuses) response = "Based on your last 200 tweets, you average %0.3f favorites and %0.3f retweets per tweet" % ( fav_per_tweet, rt_per_tweet, ) # Store data in tweets collection util.add_tweets(statuses, wilbur) return response
def update_tweets(ticker, company_name): ticker = ticker.upper() connection = util.connect_to_postgres() cursor = connection.cursor() try: cursor.execute("CALL remove_tweets(%s);", (ticker, )) except Exception as e: return {'error': str(e)} util.add_tweets(ticker, company_name, TWEEPY_API, session, connection, cursor) connection.commit() cursor.close() connection.close() return {'success': 'Successfully updated news for {}!'.format(ticker)}
def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) emoji = stats.get_emoji(statuses) if emoji == "N/A": response = "Based on your last 200 tweets, you don't seem to use emojis at all" else: response = "Based on your last 200 tweets, your most used emoji is " + emoji # Store data in tweets collection util.add_tweets(statuses, wilbur) return response
def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) mention_count = stats.get_mention_count(statuses) if len(mention_count) == 0: response = "Based on your last 200 tweets, you don't talk to anyone on twitter" else: most_mentioned = max(mention_count.iteritems(), key=operator.itemgetter(1))[0] response = "Based on your last 200 tweets, you mention @%s the most (%i)" % (most_mentioned,mention_count[most_mentioned],) # Store data in tweets collection util.add_tweets(statuses, wilbur) return response
def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) word_count = stats.get_word_count(statuses) most_used_words = sorted(word_count.iteritems(), key=operator.itemgetter(1), reverse=True)[:5] response = "Based on your last 200 tweets, your " + str(len(most_used_words)) + " most used words are " for i in range(len(most_used_words)): response = response + "'" + most_used_words[i][0] + "' " # Store data in tweets collection util.add_tweets(statuses, wilbur) return response
def process(id, text, author, wilbur): statuses = author.timeline(count=200, include_rts=False) word_count = stats.get_word_count(statuses) most_used_words = sorted(word_count.iteritems(), key=operator.itemgetter(1), reverse=True)[:5] response = "Based on your last 200 tweets, your " + str( len(most_used_words)) + " most used words are " for i in range(len(most_used_words)): response = response + "'" + most_used_words[i][0] + "' " # Store data in tweets collection util.add_tweets(statuses, wilbur) return response