def update_episodes(user, actions, now, ua_string): update_urls = [] auto_flattr = user.profile.settings.get_wksetting(FLATTR_AUTO) # group all actions by their episode for action in actions: podcast_url = action['podcast'] podcast_url = sanitize_append(podcast_url, update_urls) if podcast_url == '': continue episode_url = action['episode'] episode_url = sanitize_append(episode_url, update_urls) if episode_url == '': continue podcast = Podcast.objects.get_or_create_for_url(podcast_url) episode = Episode.objects.get_or_create_for_url(podcast, episode_url) # parse_episode_action returns a EpisodeHistoryEntry obj history = parse_episode_action(action, user, update_urls, now, ua_string) EpisodeHistoryEntry.create_entry(user, episode, history.action, history.client, history.timestamp, history.started, history.stopped, history.total, podcast_url, episode_url) if history.action == EpisodeHistoryEntry.PLAY and auto_flattr: auto_flattr_episode.delay(user, episode.id) return update_urls
def update_episodes(user, actions, now, ua_string): update_urls = [] auto_flattr = user.profile.settings.get_wksetting(FLATTR_AUTO) # group all actions by their episode for action in actions: podcast_url = action.get('podcast', '') podcast_url = sanitize_append(podcast_url, update_urls) if not podcast_url: continue episode_url = action.get('episode', '') episode_url = sanitize_append(episode_url, update_urls) if not episode_url: continue podcast = Podcast.objects.get_or_create_for_url(podcast_url) episode = Episode.objects.get_or_create_for_url(podcast, episode_url) # parse_episode_action returns a EpisodeHistoryEntry obj history = parse_episode_action(action, user, update_urls, now, ua_string) EpisodeHistoryEntry.create_entry(user, episode, history.action, history.client, history.timestamp, history.started, history.stopped, history.total, podcast_url, episode_url) if history.action == EpisodeHistoryEntry.PLAY and auto_flattr: auto_flattr_episode.delay(user.pk, episode.pk) return update_urls
def update_episodes(user, actions, now, ua_string): update_urls = [] grouped_actions = defaultdict(list) # group all actions by their episode for action in actions: podcast_url = action['podcast'] podcast_url = sanitize_append(podcast_url, update_urls) if podcast_url == '': continue episode_url = action['episode'] episode_url = sanitize_append(episode_url, update_urls) if episode_url == '': continue act = parse_episode_action(action, user, update_urls, now, ua_string) grouped_actions[ (podcast_url, episode_url) ].append(act) auto_flattr_episodes = [] # Prepare the updates for each episode state obj_funs = [] for (p_url, e_url), action_list in grouped_actions.iteritems(): episode_state = episode_state_for_ref_urls(user, p_url, e_url) if any(a['action'] == 'play' for a in actions): auto_flattr_episodes.append(episode_state.episode) fun = partial(update_episode_actions, action_list=action_list) obj_funs.append( (episode_state, fun) ) udb = get_userdata_database() bulk_save_retry(obj_funs, udb) if user.get_wksetting(FLATTR_AUTO): for episode_id in auto_flattr_episodes: auto_flattr_episode.delay(user, episode_id) return update_urls