def augment_user(user): raw_user = user._json raw_user["updated_timestamp"] = datetime.now() raw_user["created_at_timestamp"] = mongodate_to_datetime( raw_user["created_at"]) raw_user["random_number"] = random.random() return raw_user
def add_timestamp_to_tweet(tweet): """Takes a tweet dict, adds a native datetime object corresponding to tweet's 'created_at' field""" # If already defined, do nothing if TIMESTAMP_FIELD in tweet and tweet[TIMESTAMP_FIELD] != None: return if 'created_at' not in tweet: raise Exception("Tweet (id_str: {0}) has no 'created_at' field".format(tweet['id_str'])) tweet[TIMESTAMP_FIELD] = mongodate_to_datetime(tweet['created_at'])
def add_created_timestamp(user, field=ACCOUNT_CREATED_TIMESTAMP): """ Takes a user dict, adds a native datetime object corresponding to user's 'created_at' field (the time the user created the account) """ # If already defined, do nothing if field in user and user[field] != None: return if 'created_at' not in user: raise Exception("User ({0}) has no 'created_at' field".format(user)) user[field] = mongodate_to_datetime(user['created_at'])
def add_created_timestamp(user, field=ACCOUNT_CREATED_TIMESTAMP): """ Takes a user dict, adds a native datetime object corresponding to user's 'created_at' field (the time the user created the account) """ # If already defined, do nothing if field in user and user[field] != None: return if "created_at" not in user: raise Exception("User ({0}) has no 'created_at' field".format(user)) user[field] = mongodate_to_datetime(user["created_at"])
def create_userdoc_from_twitter_user(twitter_user, delete_status=True): """ Takes a fully hydrated Twitter user document, adds user collection userdoc fields, and transforms twitter user fields (created_at to timestamp, etc). twitter_user - JSON (dict) representing twitter user object Returns modified object (not strictly necessary, modifies in-place) """ # Add fields for field, default_func in userdoc_fields_defaults.items(): if field in twitter_user: continue twitter_user[field] = default_func() # Set 'created_at_timestamp' twitter_user["created_at_timestamp"] = mongodate_to_datetime(twitter_user["created_at"]) # Delete status object (conditionally) if delete_status: del(twitter_user["status"]) return twitter_user
def create_userdoc_from_twitter_user(twitter_user, delete_status=True): """ Takes a fully hydrated Twitter user document, adds user collection userdoc fields, and transforms twitter user fields (created_at to timestamp, etc). twitter_user - JSON (dict) representing twitter user object Returns modified object (not strictly necessary, modifies in-place) """ # Add fields for field, default_func in userdoc_fields_defaults.items(): if field in twitter_user: continue twitter_user[field] = default_func() # Set 'created_at_timestamp' twitter_user["created_at_timestamp"] = mongodate_to_datetime( twitter_user["created_at"]) # Delete status object (conditionally) if delete_status: del (twitter_user["status"]) return twitter_user
def augment_user(user): raw_user = user._json raw_user["updated_timestamp"] = datetime.now() raw_user["created_at_timestamp"] = mongodate_to_datetime(raw_user["created_at"]) raw_user["random_number"] = random.random() return raw_user