1 from google
.appengine
.ext
import webapp
2 from google
.appengine
.ext
.webapp
.util
import run_wsgi_app
7 import simplejson
as json
9 class MainPage(webapp
.RequestHandler
):
11 self
.response
.headers
['Content-Type'] = 'text/plain'
12 self
.response
.out
.write('Hello, webapp World!')
14 class Parse(webapp
.RequestHandler
):
20 urls
= map(urllib
.unquote
, self
.request
.get_all('url'))
22 inline_logo
= self
.request
.get_range('inline_logo', 0, 1, default
=0)
23 scale_to
= self
.request
.get_range('scale_logo', 0, 1, default
=0)
24 logo_format
= self
.request
.get('logo_format')
25 strip_html
= self
.request
.get_range('strip_html', 0, 1, default
=0)
26 use_cache
= self
.request
.get_range('use_cache', 0, 1, default
=1)
27 modified
= self
.request
.headers
.get('If-Modified-Since', None)
28 accept
= self
.request
.headers
.get('Accept', 'application/json')
31 podcasts
, last_modified
= feeddownloader
.parse_feeds(urls
, inline_logo
, scale_to
, logo_format
, strip_html
, modified
, use_cache
)
32 self
.send_response(podcasts
, last_modified
, accept
)
35 self
.response
.set_status(400)
36 self
.response
.out
.write('parameter url missing')
39 def send_response(self
, podcasts
, last_modified
, formats
):
40 self
.response
.headers
.add_header('Vary', 'Accept, User-Agent, Accept-Encoding')
42 format
= httputils
.select_matching_option(['text/html', 'application/json'], formats
)
44 if format
in (None, 'application/json'): #serve json as default
45 content_type
= 'application/json'
46 content
= json
.dumps(podcasts
, sort_keys
=True, indent
=None, separators
=(',', ':'))
47 from email
import utils
49 self
.response
.headers
.add_header('Last-Modified', utils
.formatdate(time
.mktime(last_modified
.timetuple())))
54 content_type
= 'text/html'
55 pretty_json
= json
.dumps(podcasts
, sort_keys
=True, indent
=4)
56 pretty_json
= cgi
.escape(pretty_json
)
57 content
= """<html><head>
58 <link href="static/screen.css" type="text/css" rel="stylesheet" />
59 <link href="static/prettify.css" type="text/css" rel="stylesheet" />
60 <script type="text/javascript" src="static/prettify.js"></script>
61 </head><body onload="prettyPrint()"><h1>HTML Response</h1><p>This response is HTML formatted. To get just the JSON data for processing in your client, <a href="/#accept">send the HTTP Header <em>Accept: application/json</em></a>. <a href="/">Back to the Documentation</a></p><pre class="prettyprint">%s</pre></body></html>""" % pretty_json
63 self
.response
.headers
['Content-Type'] = content_type
64 self
.response
.out
.write(content
)
67 application
= webapp
.WSGIApplication([
74 run_wsgi_app(application
)
76 if __name__
== "__main__":