本文整理汇总了Python中models.Activity._push_activity_to_userid方法的典型用法代码示例。如果您正苦于以下问题:Python Activity._push_activity_to_userid方法的具体用法?Python Activity._push_activity_to_userid怎么用?Python Activity._push_activity_to_userid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Activity
的用法示例。
在下文中一共展示了Activity._push_activity_to_userid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_activity_cards
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import _push_activity_to_userid [as 别名]
def check_activity_cards(user_id, friends=[], fofs=[], access_token=None):
"""
For a first time user, will check that the cards have activities from their friends & fofs populated
"""
user = User.get_by_id(user_id)
if (not friends) and access_token:
graph = facebook.GraphAPI(access_token)
friends = graph.get_connections("me", "friends").get('data')
#We check straight away that the friend & network cards are there
friends = [friend['id'] for friend in friends]
now = datetime.datetime.now()
created_min = now - datetime.timedelta(hours=24)
activities = col_get(ACTIVITY_, {'suggester_id' : {'$in' : friends + fofs}, 'created_on' : {'$gte' : created_min}})
match = {'user_id' : user.get('_id')}
cs = col_get(CARDSTORE, match, find='one')
cards = cs.get('cards', []) if cs else []
aids = []
for card in cards:
id_ = card.get('id', '')
if id_.startswith('a'):
aids.append(id_)
new_acts = []
for activity in activities:
act_id = activity.get('_id')
s_id = activity.get('suggester_id')
vis = activity.get('visibility')
expiry = activity.get('expiry')
keen_ids = [keen.get('user_id') for keen in activity.get('keens')]
if (act_id not in aids) and (expiry >= now) and (user_id not in keen_ids):
if (s_id in friends) or (s_id in fofs and vis == 'fof') or (vis == 'n' and user.get('network')==activity.get('network')):
new_acts.append(activity)
aids.append(act_id)
for act in new_acts:
activity_timeline_dict = {
"suggester_id" : act.get('suggester_id'),
# "created_on" : activity['created_on'],
"keyword" : act['keyword'],
"id" : 'a'+str(act['_id']), #This has to be string to consistency
"activity_hash" : act["hash"],
"confirmed" : False,
"visibility" : act.get('visibility'),
"keen" : False,
"expiry" : activity['expiry']
}
Activity._push_activity_to_userid(user.get('_id'), activity_timeline_dict)