Пример #1
0
 def addTeachedTweets(tweets):
     """ добавляет информацию о вручную определённых твиттах в базу. обновляет индексы для слов """
     print tweets
     connection = pymongo.Connection(TweetsAnalysis.connection_string,
                                     safe=True)
     results = connection.twitterAnalytic.results
     for post in tweets:
         if results.find_one("_id") is not None:
             continue
         tweet = TwitterStuff.getTweet(post)
         words = TweetsAnalysis.parseTweet(tweet['text'])
         results.save({"_id": int(post), "happy": tweets[post]})
         for word in words:
             print word
 def addTeachedTweets(self, tweets):
     """ добавляет информацию о вручную определённых твиттах в базу. обновляет индексы для слов """
     for tweetId in tweets:
         if self.tweetsColl.find_one({"_id": int(tweetId)}) is not None:
             continue
         tweet = TwitterStuff.getTweet(tweetId)
         if tweet is None:
             continue
         words = Parser().parseTweet(tweet['text'])
         words.append("@" + tweet['user']['screen_name'])
         self.tweetsColl.save({"_id": int(tweetId), "happy": tweets[tweetId]})
         for word in words:
             if len(word) < 4:
                 continue
             self.saveWord(word, tweets[tweetId])
Пример #3
0
 def addTeachedTweets(self, tweets):
     """ добавляет информацию о вручную определённых твиттах в базу. обновляет индексы для слов """
     for tweetId in tweets:
         if self.tweetsColl.find_one({"_id": int(tweetId)}) is not None:
             continue
         tweet = TwitterStuff.getTweet(tweetId)
         if tweet is None:
             continue
         words = Parser().parseTweet(tweet['text'])
         words.append("@" + tweet['user']['screen_name'])
         self.tweetsColl.save({
             "_id": int(tweetId),
             "happy": tweets[tweetId]
         })
         for word in words:
             if len(word) < 4:
                 continue
             self.saveWord(word, tweets[tweetId])
Пример #4
0
def result(request):
    """Страница отрисовки твиттов с настроениями"""

    query = request.GET.get('q', '')
    tweetsStr = request.GET.get('rpp', '')
    result_type = request.GET.get('result_type', '')
    if query is None or len(query) == 0:
        return redirect("/search?error=bad_q")
    try:
        tweetsN = int(tweetsStr)
        if tweetsN > 100:
            return redirect("/search?error=many_t")
    except:
        #return redirect("/search?error=bad_n")
        return "bad"

    result = {}
    result['tweets'] = TweetsAnalysis.predictHappiness(TwitterStuff.getTweets(query, tweetsN, result_type))
    result['query'] = query
    return render(request, 'result.html', result)