def update_related_podcasts(podcast, max_related=20): get_podcast = itemgetter(0) related = calc_similar_podcasts(podcast)[:max_related] related = map(get_podcast, related) for p in related: podcast.related_podcasts.add(p)
def update_related_podcasts(podcast, max_related=20): get_podcast = itemgetter(0) related = calc_similar_podcasts(podcast)[:max_related] related = map(get_podcast, related) for p in related: try: podcast.related_podcasts.add(p) except IntegrityError: logger.warn('Integrity error while adding related podcast', exc_info=True)
def update_related_podcasts(podcast_pk, max_related=20): get_podcast = itemgetter(0) podcast = Podcast.objects.get(pk=podcast_pk) related = calc_similar_podcasts(podcast)[:max_related] related = map(get_podcast, related) for p in related: try: podcast.related_podcasts.add(p) except IntegrityError: logger.warning("Integrity error while adding related podcast", exc_info=True)
def handle(self, *args, **options): get_podcast = itemgetter(0) max_related = options.get('max') podcasts = all_podcasts() total = podcast_count() for (n, podcast) in enumerate(podcasts): l = calc_similar_podcasts(podcast)[:max_related] related = map(get_podcast, l) update_related_podcasts(podcast, related) progress(n+1, total)
def handle(self, *args, **options): get_podcast = itemgetter(0) max_related = options.get('max') podcasts = Podcast.all_podcasts() total = Podcast.view('podcasts/by_id', limit=0).total_rows for (n, podcast) in enumerate(podcasts): l = calc_similar_podcasts(podcast)[:max_related] related = map(get_podcast, l) @repeat_on_conflict(['podcast']) def _update(podcast, related): podcast.related_podcasts = related podcast.save() _update(podcast=podcast, related=related) progress(n+1, total)