コード例 #1
0
def retrieve_tweets(mode="collection"):
    collection_name = get_collection_name(mode)
    tweets_cursor = get_mongo_db_collection(DATABASE_NAME,
                                            collection_name["tweets"]).find()
    tweets = []
    for tweet in tweets_cursor:
        tweets.append(tweet)
    return tweets
コード例 #2
0
def setup_collection(db_name, collection_name):
    """
    Sets up the collection by creating an index for it if it doesn't exist
    :param db_name: name of the database
    :param collection_name: name of the collection
    :return: the collection
    """
    collection = get_mongo_db_collection(db_name, collection_name)
    if len(collection.index_information()) < 2:
        collection.create_index([('id', ASCENDING)], unique=True)
    return collection
コード例 #3
0
def update_tweet(tweet_id, tweet_field_to_value, mode="collection"):
    collection_name = get_collection_name(mode)
    collection = get_mongo_db_collection(DATABASE_NAME,
                                         collection_name["tweets"])
    collection.update_one({'id': tweet_id}, {"$set": tweet_field_to_value})
コード例 #4
0
def fetch_tweet_by_id(tweet_id, mode="collection"):
    collection_name = get_collection_name(mode)
    tweet_cursor = get_mongo_db_collection(
        DATABASE_NAME, collection_name["tweets"]).find({'id': tweet_id})
    tweets = [tweet for tweet in tweet_cursor]
    return tweets
コード例 #5
0
def fetch_user_by_id(user_id, mode="collection"):
    collection_name = get_collection_name(mode)
    user_cursor = get_mongo_db_collection(
        DATABASE_NAME, collection_name["users"]).find({'id': user_id})
    users = [user for user in user_cursor]
    return users
コード例 #6
0
def fetch_all_places(mode="ugtweets"):
    collection_name = get_collection_name(mode)
    place_cursor = get_mongo_db_collection(DATABASE_NAME,
                                           collection_name["places"]).find({})
    places = [place for place in place_cursor]
    return places
コード例 #7
0
def fetch_all_users(mode="collection"):
    collection_name = get_collection_name(mode)
    user_cursor = get_mongo_db_collection(DATABASE_NAME,
                                          collection_name["users"]).find({})
    users = [user for user in user_cursor]
    return users