当前位置: 首页>>代码示例>>Python>>正文


Python Tweet.objects方法代码示例

本文整理汇总了Python中models.Tweet.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Tweet.objects方法的具体用法?Python Tweet.objects怎么用?Python Tweet.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Tweet的用法示例。


在下文中一共展示了Tweet.objects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_database

# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import objects [as 别名]
def update_database():
    print("fetching")
    tweets = Tweet.objects(total_fetched=1, error_occured__ne=True)
    print("updating")
    i = 0
    error_count = 0
    for each_tweet in tweets:
        print("loop")
        data = update_given_tweet(each_tweet.tweet_id)
        if not data:
            error_count += 1
            print("!!!!!!!!!error", error_count, "correct", i)
            each_tweet.error_occured = True
            each_tweet.save()
            continue
        elif data == 3:
            continue
        print("got data")
        data['fetched_timestamp'] = datetime.datetime.now()
        data['fresh_tweet'] = False
        data['update_count'] = 2
        each_tweet.total_fetched = 2
        each_tweet.tweets.append(data)
        each_tweet.save()
        print(i, "errors=", error_count)
        i += 1
开发者ID:kaflesudip,项目名称:TweetStats,代码行数:28,代码来源:update_tweets.py

示例2: render_GET

# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import objects [as 别名]
    def render_GET(self, request):
        request.setHeader("content-type", "application/json")
        tweets = Tweet.objects(entities__ne=None)
        data = []
        for tweet in tweets:
            if re.search("http://pbs.twimg.com/media/", tweet.entities):
                media_url = ast.literal_eval(tweet.entities)['media'][0]['media_url']
                data.append({'image': media_url})

        return json.dumps(data)
开发者ID:okfn-elpais-hacklabs,项目名称:server.odri.io,代码行数:12,代码来源:server.py

示例3: GetPastTweets

# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import objects [as 别名]
    def GetPastTweets(app, searchStrings):

        with app.app_context():

            auth = OAuthHandler( current_app.config['TWITTER_CONSUMER_KEY'], current_app.config['TWITTER_CONSUMER_SECRET'])
            auth.set_access_token(current_app.config['TWITTER_ACCESS_TOKEN'], current_app.config['TWITTER_ACCESS_TOKEN_SECRET'])
            api = API(auth)

            deleteEntries = connect(current_app.config['MONGODB_SETTINGS']['DB'])
            deleteEntries.drop_database(current_app.config['MONGODB_SETTINGS']['DB'])

            listTweetIDs = []

            user_query = session['userSentence']

            session['completeTweetFetch'] = False
            session['completedMetaModel'] = False

            for searchString in searchStrings:
                # Sleep for 28 secs to avoid Twitter download rate restrictions
                searchTweets = [status for status in Cursor(api.search, q=searchString).items(current_app.config['MAX_FETCH_TWEETS'])]

                for tweet in searchTweets:
                    tweet_id = tweet.id
                    if listTweetIDs.__contains__(tweet_id):
                        continue
                    if len(Tweet.objects(tweet_id=tweet_id)) > 1:
                        continue
                    tweet_message = tweet.text.encode("utf-8")
                    tweet_userhandle = tweet.user.screen_name
                    tweet_retweet_count = tweet.retweet_count
                    tweet_createtime = tweet.created_at
                    tweet_location = None
                    tweet_geo = None
                    tweet_favoritecount = tweet.favorite_count
                    tweet_username = tweet.user.name
                    tweet_user_no_of_following = tweet.user.friends_count
                    tweet_user_no_of_followers = tweet.user.followers_count
                    tweet_positiveOrnegative = 0
                    tweet_polarOrneutral = 0
                    tweet_isRetweet = 0

                    oneTweet = Tweet(tweet_id=tweet_id, tweet_msg=tweet_message, tweet_likes=tweet_favoritecount, tweet_retweets=tweet_retweet_count, tweet_search_category=searchString, tweet_user_search_query=user_query, tweet_positiveOrnegative=tweet_positiveOrnegative, tweet_polarOrneutral=tweet_polarOrneutral, tweet_user_handle=tweet_userhandle, tweet_user_name=tweet_username, tweet_user_followers=tweet_user_no_of_followers, tweet_user_following=tweet_user_no_of_following, tweet_isretweet=tweet_isRetweet, tweet_time=tweet_createtime, tweet_location=tweet_location, tweet_geo=tweet_geo)
                    oneTweet.save()
                    listTweetIDs.append(tweet_id)
                    if session['metamodelThread'] is None:
                        session['metamodelThread'] = thread.start_new_thread(twittermetamodelBuilding, ())

            print 'completed tweet fetch'
            session['completeTweetFetch'] = True
        pass
开发者ID:harsha-kadekar,项目名称:Chitralochana,代码行数:53,代码来源:DataDownloader.py

示例4: twittermetamodelBuilding

# 需要导入模块: from models import Tweet [as 别名]
# 或者: from models.Tweet import objects [as 别名]
def twittermetamodelBuilding(user_id):
    '''
    This function will be used to build the metamodel of the twitter data.
    This basically develops all the background data needed for the visualization, using Tweet data stored in DB.
    :return: -
    '''
    previouscount = 0
    userSearchObj = user_searches_ongoing[user_id]
    global TWITTER_DATA_DOWNLOADER_THREAD_INDEX
    global META_MODEL_BUILDER_THREAD_INDEX

    while(True):

        if userSearchObj.meta_model_complete and userSearchObj.tweet_fetch_complete:
            time.sleep(2)
            continue

        print userSearchObj.user_search_sentence, "From metamodel building"

        list_tweets = []
        user_tweets = {}
        hashtag_rel = {}
        list_tweets = Tweet.objects(tweet_user_search_query=userSearchObj.user_search_sentence)
        tweet_msgs_lst = []

        no_of_retweets = 0
        no_of_likes = 0
        total_posCount = 0
        total_negCount = 0

        metadata = {}

        for tweet in list_tweets:
            new_user = False
            no_of_retweets += tweet.tweet_retweets
            no_of_likes += tweet.tweet_likes

            posCount = 0
            negCount = 0

            if senana.classifier.classify(senana.feature_extractor(tweet.tweet_msg.split())) == 'positive':
                tweet.tweet_positiveOrnegative = 1
                posCount = 1
                total_posCount += 1
            else:
                tweet.tweet_positiveOrnegative = 0
                negCount = 1
                total_negCount += 1

            if user_tweets.has_key(tweet.tweet_user_handle):
                user = user_tweets[tweet.tweet_user_handle]
                user.tweet_likes += tweet.tweet_likes
                user.no_of_retweets += tweet.tweet_retweets
                user.positiveCount += posCount
                user.negativeCount += negCount
            else:
                user = Tweet_User(tweet.tweet_user_handle, tweet.tweet_user_name, tweet.tweet_user_following, tweet.tweet_user_followers, tweet.tweet_likes, tweet.tweet_retweets, posCount, negCount, 0, 0)
                user_tweets.__setitem__(tweet.tweet_user_handle, user)
                new_user = True

            tweet_msgs_lst.append(tweet.tweet_msg)

            words = tweet.tweet_msg.split(' ')
            hashtags_lst = []
            for word in words:
                if word.__len__() > 1 and word[0] == '#':
                    hashtag_string = word[1:]
                    if not re.match("^[a-zA-Z0-9]*$", hashtag_string):
                        continue
                    hashtag_string = hashtag_string.lower()
                    if hashtag_rel.has_key(hashtag_string):
                        hashtag_obj = hashtag_rel[hashtag_string]
                        hashtag_obj.no_of_retweets += tweet.tweet_retweets
                        hashtag_obj.no_of_likes += tweet.tweet_likes
                        hashtag_obj.tweets.append(tweet)
                        if new_user:
                            hashtag_obj.no_of_users += 1
                        hashtag_obj.negativeCount += negCount
                        hashtag_obj.positiveCount += posCount
                    else:
                        hashtag_obj = Twitter_Hashtag(hashtag_string, tweet.tweet_retweets, tweet.tweet_likes, 1, posCount, negCount, 0, 0)
                        hashtag_obj.tweets.append(tweet)
                        hashtag_rel.__setitem__(hashtag_string, hashtag_obj)
                    if not hashtags_lst.__contains__(hashtag_string):
                        hashtags_lst.append(hashtag_string)
                    if not user.hashtagsUsed.has_key(hashtag_string):
                        user.hashtagsUsed.__setitem__(hashtag_string, hashtag_obj)

            # print hashtags_lst
            for hashtag in hashtags_lst:
                hashtag_obj = hashtag_rel[hashtag]
                hashtag_obj.hashtag_rank = hashtag_rank_calculator(hashtag_obj.tweets.__len__(), hashtag_obj.no_of_users, hashtag_obj.no_of_retweets, hashtag_obj.no_of_likes)
                for otherhashtag in hashtags_lst:
                    if otherhashtag == hashtag:
                        continue
                    if not hashtag_obj.related_hashtags.has_key(otherhashtag):
                        hashtag_obj.related_hashtags.__setitem__(otherhashtag, hashtag_rel[otherhashtag])

        full_hashtags = ''
        topfiveHashtags = []
#.........这里部分代码省略.........
开发者ID:harsha-kadekar,项目名称:Chitralochana,代码行数:103,代码来源:twitter.py


注:本文中的models.Tweet.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。