1 from google
.appengine
.ext
import webapp
2 from google
.appengine
.ext
.webapp
.util
import run_wsgi_app
6 import simplejson
as json
8 class MainPage(webapp
.RequestHandler
):
10 self
.response
.headers
['Content-Type'] = 'text/plain'
11 self
.response
.out
.write('Hello, webapp World!')
13 class Parse(webapp
.RequestHandler
):
19 urls
= self
.request
.get_all('url')
20 urls
= map(urllib
.unquote
, urls
)
21 inline_logo
= self
.request
.get_range('inline_logo', 0, 1, default
=0)
22 scale_to
= self
.request
.get_range('scale_logo', 0, 1, default
=0)
23 strip_html
= self
.request
.get_range('strip_html', 0, 1, default
=0)
24 modified
= self
.request
.headers
.get('If-Modified-Since', None)
25 accept
= self
.request
.headers
.get('Accept', 'application/json')
28 podcasts
, last_modified
= feeddownloader
.parse_feeds(urls
, inline_logo
, scale_to
, strip_html
, modified
)
29 self
.send_response(podcasts
, last_modified
, accept
)
32 self
.response
.set_status(400)
33 self
.response
.out
.write('parameter url missing')
36 def send_response(self
, podcasts
, last_modified
, format
):
37 self
.response
.headers
.add_header('Vary', 'Accept')
40 content_type
= 'application/json'
41 content
= json
.dumps(podcasts
, sort_keys
=True, indent
=None, separators
=(',', ':'))
42 from email
import utils
44 self
.response
.headers
.add_header('Last-Modified', utils
.formatdate(time
.mktime(last_modified
)))
49 content_type
= 'text/html'
50 pretty_json
= json
.dumps(podcasts
, sort_keys
=True, indent
=4)
51 pretty_json
= cgi
.escape(pretty_json
)
52 content
= """<html><head>
53 <link href="static/screen.css" type="text/css" rel="stylesheet" />
54 <link href="static/prettify.css" type="text/css" rel="stylesheet" />
55 <script type="text/javascript" src="static/prettify.js"></script>
56 </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
58 self
.response
.headers
['Content-Type'] = content_type
59 self
.response
.out
.write(content
)
62 application
= webapp
.WSGIApplication([
69 run_wsgi_app(application
)
71 if __name__
== "__main__":