def get_filtered_friends_timeline(request): prof = request.user.get_profile() tp = TwitterUserProfile.objects.get(user=prof) twitter_tokens = request.session['twitter_tokens'] api = get_authorized_twython(twitter_tokens) statuses = Status.construct_from_dicts(api.getFriendsTimeline()) predictions = get_predictions(tp, statuses) filtered_statuses = [] for s, r in zip(statuses, predictions): if r >= 0: filtered_statuses.append(s) Rating.appendTo(statuses, tp) return {'statuses': filtered_statuses, 'feedtype': 'filter'}
def cache_statuses(statuses, tp): s_ids = [s.id for s in statuses] s_cached = set([s.id for s in tp.cached_statuses.filter(id__in=s_ids)]) Status.savemany(statuses, is_cached=True) usercache_statuses = [] for s in statuses: if s.id in s_cached: continue s_cached.add(s.id) usercache_statuses.append(s) predictions = get_predictions(tp, usercache_statuses) CachedStatus.objects.create_in_bulk(tp, usercache_statuses, predictions)
def predicted_friends_timeline(request): prof = request.user.get_profile() tp = TwitterUserProfile.objects.get(user=prof) twitter_tokens = request.session['twitter_tokens'] api = get_authorized_twython(twitter_tokens) statuses = Status.construct_from_dicts(api.getFriendsTimeline()) friends = api.getFriendsStatus() predictions = get_predictions(tp, statuses) for s, r in zip(statuses, predictions): if r >= 0: s.likeClass = ' active' s.dislikeClass = ' inactive' if r < 0: s.likeClass = ' inactive' s.dislikeClass = ' active' return {'statuses': statuses, 'friends': friends, 'feedtype': 'predict'}