本文整理汇总了Python中mygpo.core.models.Podcast.for_url方法的典型用法代码示例。如果您正苦于以下问题:Python Podcast.for_url方法的具体用法?Python Podcast.for_url怎么用?Python Podcast.for_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mygpo.core.models.Podcast
的用法示例。
在下文中一共展示了Podcast.for_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search_podcasts
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def search_podcasts(q, limit=20, skip=0):
if is_url(q):
url = sanitize_url(q)
podcast = Podcast.for_url(url, create=True)
if not podcast.title:
update_podcasts([podcast])
podcast = Podcast.for_url(url)
return [podcast], 1
db = get_main_database()
#FIXME current couchdbkit can't parse responses for multi-query searches
q = q.replace(',', '')
res = db.search('podcasts/search', wrapper=search_wrapper,
include_docs=True, limit=limit, skip=skip, q=q,
sort='\\subscribers<int>')
#FIXME: return empty results in case of search backend error
try:
return list(res), res.total_rows
except:
return [], 0
示例2: handle
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def handle(self, *args, **options):
if len(args) != 5:
print 'Usage: ./manage.py group-podcasts <url1> <url2> <group-name> <name1> <name2>'
return
p1_url = args[0]
p2_url = args[1]
group_title = args[2]
myname = args[3]
othername = args[4]
p1 = Podcast.for_url(p1_url)
p2 = Podcast.for_url(p2_url)
p1.group_with(p2, group_title, myname, othername)
示例3: list_favorites
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def list_favorites(request):
site = RequestSite(request)
episodes = backend.get_favorites(request.user)
podcast_ids = [episode.podcast for episode in episodes]
podcasts = get_to_dict(Podcast, podcast_ids, Podcast.get_id)
def set_podcast(episode):
episode = proxy_object(episode)
episode.podcast = podcasts.get(episode.podcast, None)
return episode
episodes = map(set_podcast, episodes)
feed_url = 'http://%s/%s' % (site.domain, reverse('favorites-feed', args=[request.user.username]))
podcast = Podcast.for_url(feed_url)
if 'public_feed' in request.GET:
request.user.favorite_feeds_token = ''
request.user.save()
elif 'private_feed' in request.GET:
request.user.create_new_token('favorite_feeds_token', 8)
request.user.save()
token = request.user.favorite_feeds_token
return render(request, 'favorites.html', {
'episodes': episodes,
'feed_token': token,
'site': site,
'podcast': podcast,
})
示例4: create
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def create(request, username, format):
""" Creates a new podcast list and links to it in the Location header """
title = request.GET.get('title', None)
if not title:
return HttpResponseBadRequest('Title missing')
slug = slugify(title)
if not slug:
return HttpResponseBadRequest('Invalid title')
plist = PodcastList.for_user_slug(request.user._id, slug)
if plist:
return HttpResponse('List already exists', status=409)
urls = parse_subscription(request.raw_post_data, format)
podcasts = [Podcast.for_url(url, create=True) for url in urls]
podcast_ids = map(Podcast.get_id, podcasts)
plist = PodcastList()
plist.title = title
plist.slug = slug
plist.user = request.user._id
plist.podcasts = podcast_ids
plist.save()
response = HttpResponse(status=201)
list_url = reverse('api-get-list', args=[request.user.username, slug, format])
response['Location'] = list_url
return response
示例5: _get_podcasts
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def _get_podcasts(self, request):
podcasts = []
for n in count():
podcast_url = request.POST.get('feed%d' % n, None)
if podcast_url is None:
break
if not podcast_url:
continue
podcast = Podcast.for_url(podcast_url)
if not podcast:
raise InvalidPodcast(podcast_url)
podcasts.append(Podcast.for_url(podcast_url))
return podcasts
示例6: podcast_info
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def podcast_info(request):
url = sanitize_url(request.GET.get('url', ''))
podcast = Podcast.for_url(url)
if not podcast:
raise Http404
domain = RequestSite(request).domain
resp = podcast_data(podcast, domain)
return JsonResponse(resp)
示例7: _get_obj_fun
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def _get_obj_fun(self, action):
url, op = action
podcast = self.podcasts.get(url, Podcast.for_url(url, create=True))
state = podcast.get_user_state(self.user)
fun = self.operations[op]
return (state, fun)
示例8: episodes
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def episodes(request, username, version=1):
version = int(version)
now = datetime.now()
now_ = get_timestamp(now)
ua_string = request.META.get('HTTP_USER_AGENT', '')
if request.method == 'POST':
try:
actions = json.loads(request.raw_post_data)
except (JSONDecodeError, UnicodeDecodeError) as e:
log('Advanced API: could not decode episode update POST data for user %s: %s' % (username, e))
return HttpResponseBadRequest()
try:
update_urls = update_episodes(request.user, actions, now, ua_string)
except DeviceUIDException as e:
import traceback
log('could not update episodes for user %s: %s %s: %s' % (username, e, traceback.format_exc(), actions))
return HttpResponseBadRequest(str(e))
return JsonResponse({'timestamp': now_, 'update_urls': update_urls})
elif request.method == 'GET':
podcast_url= request.GET.get('podcast', None)
device_uid = request.GET.get('device', None)
since_ = request.GET.get('since', None)
aggregated = parse_bool(request.GET.get('aggregated', False))
try:
since = datetime.fromtimestamp(float(since_)) if since_ else None
except ValueError:
return HttpResponseBadRequest('since-value is not a valid timestamp')
if podcast_url:
podcast = Podcast.for_url(podcast_url)
if not podcast:
raise Http404
else:
podcast = None
if device_uid:
try:
device = request.user.get_device_by_uid(device_uid)
except DeviceDoesNotExist as e:
return HttpResponseNotFound(str(e))
else:
device = None
changes = get_episode_changes(request.user, podcast, device, since,
now, aggregated, version)
return JsonResponse(changes)
示例9: search_podcast
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def search_podcast(request):
form = SearchPodcastForm(request.POST)
if form.is_valid():
url = form.cleaned_data['url']
podcast = Podcast.for_url(url)
if not podcast:
raise Http404
url = get_podcast_link_target(podcast, 'podcast-publisher-detail')
else:
url = reverse('publisher')
return HttpResponseRedirect(url)
示例10: subscribe_url
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def subscribe_url(request):
url = request.GET.get('url', None)
if not url:
raise Http404('http://my.gpodder.org/subscribe?url=http://www.example.com/podcast.xml')
url = sanitize_url(url)
if url == '':
raise Http404('Please specify a valid url')
podcast = Podcast.for_url(url, create=True)
return HttpResponseRedirect(get_podcast_link_target(podcast, 'subscribe'))
示例11: handle
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def handle(self, *args, **options):
urls = list(map(str.strip, fileinput.input(args)))
try:
examples = ExamplePodcasts.get(EXAMPLES_DOCID)
except ResourceNotFound:
examples = ExamplePodcasts()
examples._id = EXAMPLES_DOCID
podcasts = filter(None, [Podcast.for_url(url) for url in urls])
examples.podcast_ids = [podcast.get_id() for podcast in podcasts]
examples.updated = datetime.utcnow()
examples.save()
示例12: _get_podcasts
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def _get_podcasts(self, *args, **options):
if options.get('toplist'):
yield self.get_toplist()
if options.get('new'):
yield self.get_podcast_with_new_episodes()
if options.get('random'):
yield Podcast.random()
get_podcast = lambda url: Podcast.for_url(url, create=True)
yield map(get_podcast, args)
if not args and not options.get('toplist') and not options.get('new') \
and not options.get('random'):
yield Podcast.by_last_update()
示例13: upload
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def upload(request):
try:
emailaddr = request.POST['username']
password = request.POST['password']
action = request.POST['action']
protocol = request.POST['protocol']
opml = request.FILES['opml'].read()
except MultiValueDictKeyError:
return HttpResponse("@PROTOERROR", mimetype='text/plain')
user = auth(emailaddr, password)
if (not user):
return HttpResponse('@AUTHFAIL', mimetype='text/plain')
dev = get_device(user, LEGACY_DEVICE_UID,
request.META.get('HTTP_USER_AGENT', ''))
existing_urls = [x.url for x in dev.get_subscribed_podcasts()]
i = Importer(opml)
podcast_urls = [p['url'] for p in i.items]
podcast_urls = sanitize_urls(podcast_urls)
podcast_urls = filter(lambda x: x, podcast_urls)
new = [u for u in podcast_urls if u not in existing_urls]
rem = [u for e in existing_urls if u not in podcast_urls]
#remove duplicates
new = list(set(new))
rem = list(set(rem))
for n in new:
try:
p = Podcast.for_url(n, create=True)
except IntegrityError, e:
log('/upload: Error trying to get podcast object: %s (error: %s)' % (n, e))
continue
try:
p.subscribe(user, dev)
except Exception as e:
log('Legacy API: %(username)s: could not subscribe to podcast %(podcast_url)s on device %(device_id)s: %(exception)s' %
{'username': user.username, 'podcast_url': p.url, 'device_id': dev.id, 'exception': e})
示例14: update_list
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def update_list(request, plist, owner, format):
""" Replaces the podcasts in the list and returns 204 No Content """
is_own = owner == request.uuser
if not is_own:
return HttpResponseForbidden()
urls = parse_subscription(request.raw_post_data, format)
podcasts = [Podcast.for_url(url, create=True) for url in urls]
podcast_ids = map(Podcast.get_id, podcasts)
@repeat_on_conflict(['podcast_ids'])
def _update(plist, podcast_ids):
plist.podcasts = podcast_ids
plist.save()
_update(plist=plist, podcast_ids=podcast_ids)
return HttpResponse(status=204)
示例15: podcast_settings
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import for_url [as 别名]
def podcast_settings(user, url):
podcast = Podcast.for_url(url)
if not podcast:
raise Http404
obj = PodcastUserState.for_user_podcast(user, podcast)
return obj, obj