Permalink
Browse files

now also able to return feed info from a feed url. quite useful for A…

…PI that don't want to bother and just get a user entered url
  • Loading branch information...
1 parent 0df650e commit f5faaa31507dda51f5a59ac06eb49dd55f3cdc14 @julien51 julien51 committed Mar 9, 2012
Showing with 3,911 additions and 1 deletion.
  1. BIN extractlinks.pyc
  2. +3,900 −0 feedparser.py
  3. BIN feedparser.pyc
  4. +11 −1 main.py
View
Binary file not shown.
View
View
Binary file not shown.
View
@@ -29,6 +29,8 @@
import extractlinks
from extractlinks import LinkExtractor
+import feedparser
+import re
class MainHandler(webapp.RequestHandler):
@@ -53,9 +55,17 @@ def get(self):
parser.set_base_url(site_url)
parser.feed(result.content)
feeds = parser.links
+ if not feeds:
+ # Let's check if by any chance this is actually not a feed?
+ data = feedparser.parse(result.content)
+ mimeType = "application/atom+xml"
+ href = site_url
+ if re.match("atom", data.version):
+ mimeType = "application/atom+xml"
+ feeds = [{'title': data.feed.title, 'rel': 'self', 'type': mimeType, 'href': href}]
+
if not memcache.add(site_url, feeds, 604800):
logging.error("Memcache set failed.")
-
self.render_json(feeds)
except:
self.render_json([])

0 comments on commit f5faaa3

Please sign in to comment.