follow RSS-Redirects and parse new location
[mygpo-feedservice.git] / feedservice / main.py
blobea7ebc542f4fcfec7fc72baa9e8b3dc5d7176665
1 from google.appengine.ext import webapp
2 from google.appengine.ext.webapp.util import run_wsgi_app
4 import urllib
5 import feeddownloader
6 import simplejson as json
8 class MainPage(webapp.RequestHandler):
9 def get(self):
10 self.response.headers['Content-Type'] = 'text/plain'
11 self.response.out.write('Hello, webapp World!')
13 class Parse(webapp.RequestHandler):
15 def post(self):
16 return self.get()
18 def get(self):
19 self.response.headers['Content-Type'] = 'text/plain'
20 urls = self.request.get_all('url')
21 urls = map(urllib.unquote, urls)
22 inline_logo = self.get_int('inline_logo')
23 scale_to = self.get_int('scale_logo', None)
25 if urls:
26 podcasts = feeddownloader.parse_feeds(urls, inline_logo, scale_to)
27 pretty = json.dumps(podcasts, sort_keys=True, indent=4)
28 self.response.out.write(pretty)
29 else:
30 self.response.set_status(400)
31 self.response.out.write('parameter url missing')
33 def get_int(self, param, default=0):
34 try:
35 return int(self.request.get(param, default))
36 except:
37 return default
40 application = webapp.WSGIApplication([
41 ('/', MainPage),
42 ('/parse', Parse)
44 debug=True)
46 def main():
47 run_wsgi_app(application)
49 if __name__ == "__main__":
50 main()