def handle(self, *args, **options): # couchdbkit doesn't preserve microseconds start_time = datetime.utcnow().replace(microsecond=0) excluded_tags = settings.DIRECTORY_EXCLUDED_TAGS tags = args or Tag.all() for n, tag in enumerate(tags): if not isinstance(tag, basestring): tag = str(tag) label = utils.remove_control_chars(tag.strip()) if not label: continue tag_obj = Tag(tag) podcast_ids, weights = utils.unzip(list(tag_obj.get_podcasts())) podcast_objs = Podcast.get_multi(podcast_ids) podcasts = [] for podcast, weight in zip(podcast_objs, weights): e = CategoryEntry() e.podcast = podcast.get_id() e.weight = float(weight * podcast.subscriber_count()) podcasts.append(e) category = Category.for_tag(label) if not category: if not label or label in excluded_tags: continue category = Category() category.label = label category.spellings = [] # delete if it has been excluded after it has been created if label in excluded_tags: category.delete() continue # we overwrite previous data if category.updated != start_time: category.podcasts = [] category.merge_podcasts(podcasts) category.updated = start_time if 'weight' in category: del category['weight'] category.save() try: utils.progress(n % 1000, 1000, category.label.encode('utf-8')) except: pass
def example_podcasts(request, format): podcasts = cache.get('example-podcasts', None) try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') if scale not in range(1, 257): return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256') if not podcasts: try: examples = ExamplePodcasts.get('example_podcasts') ids = examples.podcast_ids podcasts = list(Podcast.get_multi(ids)) cache.set('example-podcasts', podcasts) except ResourceNotFound: podcasts = [] title = 'gPodder Podcast Directory' domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list( podcasts, format, title, json_map=p_data, xml_template='podcasts.xml', request=request, )
def _prepare_list(self, l): podcasts = Podcast.get_multi(l.podcasts[:self.podcasts_per_topic]) user = User.get(l.user) l = proxy_object(l) l.podcasts = podcasts l.username = user.username l.cls = "PodcastList" return l
def get_podcasts(self, count=None): user = User.get(self.user) subscriptions = user.get_subscribed_podcast_ids() ids = filter(lambda x: not x in self.blacklist + subscriptions, self.podcasts) if count: ids = ids[:count] return filter(lambda x: x and x.title, Podcast.get_multi(ids))
def update_published_podcasts(request, username): user = User.get_user(username) if not user: raise Http404 published_podcasts = Podcast.get_multi(user.published_objects) update_podcasts(published_podcasts) return HttpResponse('Updated:\n' + '\n'.join([p.url for p in published_podcasts]), mimetype='text/plain')
def get_podcasts(self, start=0, end=20): cache_id = 'category-%s' % self._id podcasts = cache.get(cache_id, []) if len(podcasts) < end: ids = self.get_podcast_ids(len(podcasts), end) podcasts.extend(list(Podcast.get_multi(ids))) cache.set(cache_id, podcasts) return podcasts[start:end]
def home(request): if is_publisher(request.user): podcasts = Podcast.get_multi(request.user.published_objects) form = SearchPodcastForm() return render(request, 'publisher/home.html', { 'podcasts': podcasts, 'form': form, }) else: site = RequestSite(request) return render(request, 'publisher/info.html', { 'site': site })
def get_list(request, plist, owner, format): """ Returns the contents of the podcast list """ try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') podcasts = Podcast.get_multi(plist.podcasts) domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) title = '{title} by {username}'.format(title=plist.title, username=owner.username) return format_podcast_list(podcasts, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp', ''), xml_template='podcasts.xml', request=request)
def list_show(request, plist, owner): is_own = owner == request.user plist = proxy_object(plist) podcasts = list(Podcast.get_multi(plist.podcasts)) plist.podcasts = podcasts max_subscribers = max([p.subscriber_count() for p in podcasts] + [0]) site = RequestSite(request) return render( request, "list.html", { "podcastlist": plist, "max_subscribers": max_subscribers, "owner": owner, "domain": site.domain, "is_own": is_own, }, )
def list_opml(request, plist, owner): podcasts = list(Podcast.get_multi(plist.podcasts)) return format_podcast_list(podcasts, "opml", plist.title)
def get_subscribed_podcasts(self, public=None): return set(Podcast.get_multi(self.get_subscribed_podcast_ids(public=public)))
def get_subscribed_podcasts(self): return set(Podcast.get_multi(self.get_subscribed_podcast_ids()))