Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit f5faaa31507dda51f5a59ac06eb49dd55f3cdc14 1 parent 0df650e
Julien Genestoux authored March 09, 2012
BIN  extractlinks.pyc
Binary file not shown
3,900  feedparser.py
3900 additions, 0 deletions not shown
BIN  feedparser.pyc
Binary file not shown
12  main.py
@@ -29,6 +29,8 @@
29 29
 
30 30
 import extractlinks
31 31
 from extractlinks import LinkExtractor 
  32
+import feedparser
  33
+import re
32 34
 
33 35
 class MainHandler(webapp.RequestHandler):
34 36
   
@@ -53,9 +55,17 @@ def get(self):
53 55
           parser.set_base_url(site_url)
54 56
           parser.feed(result.content)
55 57
           feeds  = parser.links
  58
+          if not feeds:
  59
+              # Let's check if by any chance this is actually not a feed?
  60
+              data = feedparser.parse(result.content)
  61
+              mimeType = "application/atom+xml"
  62
+              href = site_url
  63
+              if re.match("atom", data.version):
  64
+                  mimeType = "application/atom+xml"
  65
+              feeds = [{'title': data.feed.title, 'rel': 'self', 'type': mimeType, 'href': href}]
  66
+              
56 67
           if not memcache.add(site_url, feeds, 604800):
57 68
             logging.error("Memcache set failed.")
58  
-            
59 69
           self.render_json(feeds)
60 70
         except:
61 71
           self.render_json([])

0 notes on commit f5faaa3

Please sign in to comment.
Something went wrong with that request. Please try again.