def subscriberdata_for_podcast(podcast_id): if not podcast_id: raise QueryParameterMissing('podcast_id') db = get_main_database() data = get_single_result(db, 'podcasts/subscriber_data', key = podcast_id, include_docs = True, schema = PodcastSubscriberData, ) if not data: data = PodcastSubscriberData() data.podcast = podcast_id return data
def handle(self, *args, **options): total = Podcast.count() podcasts = Podcast.all_podcasts() actions = Counter() for n, podcast in enumerate(podcasts): psubscriber = PodcastSubscriberData.for_podcast(podcast.get_id()) res = self.update_subscriber_data(podcast, data=psubscriber) self.update_podcast(podcast=podcast) action = 'updated' if res else 'skipped' actions[action] += 1 status_str = ', '.join('%s: %d' % x for x in actions.items()) progress(n+1, total, status_str)