def get_index(): # call get_tweets from the tweet module, sotre the result in a variable called tweets tweets = get_tweets() # return the result of the function template, pass two parameters to template() # the first parameter is the name of our html file in a string, simple.html, but leave # off the .html # the second is a named parameter, call it tweets and assign tweets to it return template('simple',tweets=tweets)
def accuracytest(classifier_class, debug=False, nwords=2500): num_tweets, tweets = get_tweets() (train, test) = partition_tweets(tweets) corpus = [t.text for t in tweets] vocabulary = most_common_words(corpus, nwords) [t.load_freq_list(vocabulary) for t in tweets] classifier = classifier_class(train, vocabulary) return num_tweets, classifier.accuracy(train), classifier.accuracy(test)
def accuracytest(classifier_class, debug=False, nwords=2500): tweets = get_tweets() (train, test) = partition_tweets(tweets) corpus = [t.text for t in tweets] vocabulary = most_common_words(corpus, nwords) [t.load_freq_list(vocabulary) for t in tweets] classifier = classifier_class(train, vocabulary) print "Vocabulary size: %d" % nwords print("Accuracy of classifier in train set: %.3f" % classifier.accuracy(train)) print("Accuracy of classifier in test set: %.3f" % classifier.accuracy(test))
def index(): keyword = request.args.get('keyword') if keyword: my_tweets = get_tweets(keyword) sentiments = polarity(my_tweets, keyword) else: my_tweets = [] sentiments = {} return render_template('index.html', tweets=my_tweets, sentiments=sentiments)
def tweet(): # notice that we're pulling the value of tweet-status from the request # this is what you typed into the web form tweet_status = request.forms.get('tweet-status') # call post_tweet from module tweet, pass in the tweet_status post_tweet(tweet_status) # call get_tweets from the tweet module, sotre the result in a variable called tweets tweets = get_tweets() # just as you did in the get_index() function call template and return its result return template('simple', tweets=tweets)
def getTweets(self): self.check_reply = "" self.tweetitems = [] self.hash = config.get_setting("search_livemoto") if not self.hash: self.hash = "@movistar_motogp" import tweet if self.hash.startswith("#"): tweets = tweet.get_tweets(None, self.hash, None, None, max_id=self.last_id) elif self.hash.startswith("@"): try: tweets, total = tweet.get_tweets(self.hash, None, None, None, max_id=self.last_id) except: tweets = None else: tweets = tweet.get_tweets(None, None, self.hash, None, max_id=self.last_id) if tweets: self.last_id = tweets[-1]['id'] for _tweet in tweets: video_link = _tweet["videos"] try: video = video_link[0]["url"] except: video = "" try: images = ", ".join(_tweet["images"]) except: images = [] pepe = _tweet["twittercl"] td = self.get_timedelta_string(datetime.datetime.utcnow() - _tweet["date"]) text = _tweet["text"].replace("\n", " ") phrase = _tweet["phrase"].replace("\n", " ") try: item = xbmcgui.ListItem(text) except: try: item = xbmcgui.ListItem(text.encode('unicode-escape')) except: item = xbmcgui.ListItem( "Error cargando tweet...lo sentimos :(") item.setProperty("profilepic", _tweet["profilepic"]) item.setProperty("author_rn", "[B]" + _tweet["author_rn"] + "[/B]") item.setProperty("author", "[B]" + "@" + _tweet["author"] + "[/B]") item.setProperty("timedelta", td) banner = _tweet["banner"] item.setProperty("text", text) item.setProperty("phrase", phrase) item.setProperty("twittercl", str(_tweet["twittercl"])) item.setProperty("url", str(_tweet["url"])) item.setProperty("banner", banner) item.setProperty("fav", _tweet["fav"]) item.setProperty("rt", _tweet["rt"]) item.setProperty("profilepic_rt", _tweet["profilepic_rt"]) item.setProperty("profilepic_rtr", _tweet["profilepic_rtr"]) item.setProperty("reply_rt", _tweet["reply_rt"]) item.setProperty("banner_rt", _tweet["banner_rt"]) item.setProperty("videos", video) item.setProperty("images", images) item.setProperty("profilepic_toreply", _tweet["profilepic_toreply"]) item.setProperty("text_toreply", _tweet["text_toreply"]) item.setProperty("mention_text", _tweet["mention_text"]) item.setProperty("mention_profilepic", _tweet["mention_profilepic"]) item.setProperty("mention_banner", _tweet["mention_banner"]) item.setProperty("mention_url", str(_tweet["mention_url"])) item.setProperty("rt_rt", _tweet["rt_rt"]) item.setProperty("fav_rt", _tweet["fav_rt"]) item.setProperty("mention_rt", str(_tweet["mention_rt"])) item.setProperty("mention_fav", str(_tweet["mention_fav"])) item.setProperty( "mention_name", "[B]" + "@" + str(_tweet["mention_name"]) + "[/B]") item.setProperty( "name_toreply", "[B]" + "@" + str(_tweet["name_toreply"]) + "[/B]") item.setProperty("name_rt", "[B]" + "@" + str(_tweet["name_rt"]) + "[/B]") item.setProperty("text_rt", _tweet["text_rt"]) item.setProperty("minm_text", _tweet["minm_text"]) item.setProperty("minm_name", _tweet["minm_name"]) item.setProperty("minm_profilepic", _tweet["minm_profilepic"]) item.setProperty("followers", str(_tweet["followers"])) item.setProperty("friends", str(_tweet["friends"])) item.setProperty("location", _tweet["location"]) item.setProperty("go_tweet", unicode(_tweet["go_tweet"])) item.setProperty("thumb", _tweet["thumb"]) self.tweetitems.append(item) self.getControl(32507).reset() if self.tweetitems: self.getControl(32507).addItem(self.tweetitems[0]) return
def requestResults(user1,user2): nusers,wc,df=get_tweets(user1,user2) return nusers,wc,df
if __name__ == "__main__": mentions = api.GetMentions(count=1) since_id = mentions[0].id print(mentions, since_id) username = mentions[0].user.screen_name while True: if len(mentions) >= 1: for mention in mentions: username = mention.user.screen_name since_id = mention.id # Get tweets tweets = tweet.get_tweets(username, 2000) tweets_text = process.get_text(tweets) # Process tweets for wordcloud wordcloud_data = process.list_to_str(tweets_text) process.generate_wordcloud(wordcloud_data) # Reply with wordcloud api.PostUpdate(status="Hello @{}, I am a bot".format(username), media="wordcloud.png", in_reply_to_status_id=since_id) # Get new messages mentions = api.GetMentions(since_id=since_id) time.sleep(5)
def tweet_data(keyword): my_tweets = get_tweets(keyword) sentiments = polarity(my_tweets, keyword) data = db[keyword] print(data) return (jsonify({"sentiments": sentiments, "tweets": my_tweets}))
# Store the tweets here combined = [] try: since_id = sys.argv[4] except: since_id = None # Open classifier classifier = pickle.load(open("classifier.pickle", "rb")) start = time.time() # Get the tweets if since_id is None: tweets = tweet.get_tweets(lat=lat, long=long, radius=radius, term=" flu ", count=1000) else: tweets = tweet.get_tweets(lat=lat, long=long, radius=radius, term=" flu ", count=1000, since_id=since_id) print(str(len(tweets)) + ' new tweets have been pulled') print('Running classifier') # Classify the tweets classifications = classifier.classify_many([classify.get_features(x['text']) for x in tweets]) print('All tweets have been classified') # Converting the tweets to the form for the mapper for i in range(len(tweets)): temp = {} temp['time'] = tweets[i]['time']
def requestResults(name): tweets = get_tweets(name) return tweets
def requestResults(user1, user2): nusers, wc, df, todayGraph = get_tweets(user1, user2) return nusers, wc, df, todayGraph