Add "fb:" prefix shortcut for feed URLs

It's now possible to have some prefix shortcuts
when adding URLs. This should make the life of
lazy typists easier, especially on mobile devices.

At the moment, the only available prefix is "fb:".
If you want to add a FeedBurner URL, simply take
the name of the podcast and prefix it with "fb:".

Added some doctests to normalize_feed_url.
This commit is contained in:
Thomas Perl 2009-11-03 19:15:16 +01:00
parent 0e5f2f49a9
commit 5115f7119e
1 changed files with 24 additions and 1 deletions

View File

@ -113,13 +113,36 @@ def normalize_feed_url(url):
Also supported are phobos.apple.com links (iTunes podcast)
and itms:// links (iTunes podcast direct link).
>>> normalize_feed_url('itpc://example.org/podcast.rss')
'http://example.org/podcast.rss'
If no URL scheme is defined (e.g. "curry.com"), we will
simply assume the user intends to add a http:// feed.
"""
>>> normalize_feed_url('curry.com')
'http://curry.com'
There are even some more shortcuts for advanced users
and lazy typists (see the source for details).
>>> normalize_feed_url('fb:43FPodcast')
'http://feeds2.feedburner.com/43FPodcast'
"""
if not url or len(url) < 8:
return None
# This is a list of prefixes that you can use to minimize the amount of
# keystrokes that you have to use.
# Feel free to suggest other useful prefixes, and I'll add them here.
PREFIXES = {
'fb:': 'http://feeds2.feedburner.com/%s',
}
for prefix, expansion in PREFIXES.iteritems():
if url.startswith(prefix):
url = expansion % (url[len(prefix):],)
break
# Assume HTTP for URLs without scheme
if not '://' in url:
url = 'http://' + url