Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 81 lines (60 sloc) 2.463 kB
ae75674 @arantius Initial checkin, partially working.
authored
1 #!/usr/bin/env python
fac37bf @arantius Clean up module docsstrings.
authored
2 """App Engine request handler for Readability API project.
3
4 --------------------------------------------------------------------------------
ae75674 @arantius Initial checkin, partially working.
authored
5
7276d09 @arantius Clean up licensing a bit.
authored
6 Readability API - Clean up pages and feeds to be readable.
7 Copyright (C) 2010 Anthony Lieuallen
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 """
ae75674 @arantius Initial checkin, partially working.
authored
22
91a33fe @arantius Syntax/lint clean ups.
authored
23 from email import utils as email_utils # pylint: disable-msg=E0611,C6202
35c89c2 @arantius Use logging.debug(), set that level visible in dev_appserver.
authored
24 import logging
ae75674 @arantius Initial checkin, partially working.
authored
25 import os
c4eebdc @arantius Send caching headers.
authored
26 import time
ae75674 @arantius Initial checkin, partially working.
authored
27
28 from google.appengine.ext import webapp
29 from google.appengine.ext.webapp import template
30 from google.appengine.ext.webapp.util import run_wsgi_app
31
32 import clean
af2b102 @arantius Feed cleaning. Coerce everything to unicode.
authored
33 import util
ae75674 @arantius Initial checkin, partially working.
authored
34
5add88c @arantius Only check whether we're running in dev appserver once.
authored
35 if util.IS_DEV_APPSERVER:
35c89c2 @arantius Use logging.debug(), set that level visible in dev_appserver.
authored
36 logging.getLogger().setLevel(logging.DEBUG)
a3f51fb @arantius Lighter logging, catch urlfetch exceptions in prod.
authored
37 else:
38 logging.getLogger().setLevel(logging.WARNING)
35c89c2 @arantius Use logging.debug(), set that level visible in dev_appserver.
authored
39
ae75674 @arantius Initial checkin, partially working.
authored
40
41 class MainPage(webapp.RequestHandler):
0287796 @arantius Syntax/lint tweaks.
authored
42 request = None
43 response = None
44
ae75674 @arantius Initial checkin, partially working.
authored
45 def get(self):
46 self.response.headers['Content-Type'] = 'text/html'
47 path = os.path.join(os.path.dirname(__file__), 'templates/main.html')
48 self.response.out.write(template.render(path, {}))
49
50
af2b102 @arantius Feed cleaning. Coerce everything to unicode.
authored
51 class Clean(webapp.RequestHandler):
0287796 @arantius Syntax/lint tweaks.
authored
52 request = None
53 response = None
54
ae75674 @arantius Initial checkin, partially working.
authored
55 def get(self):
f2d16b3 @arantius Revert "Feed cleaning. Coerce everything to unicode."
authored
56 url = self.request.get('url') or self.request.get('link')
57 html_wrap = self.request.get('html_wrap', 'False') == 'True'
58 if url:
59 output = clean.Clean(url)
60 if html_wrap:
61 output = u'<html><body>\n%s\n</body></html>' % output
af2b102 @arantius Feed cleaning. Coerce everything to unicode.
authored
62 else:
f2d16b3 @arantius Revert "Feed cleaning. Coerce everything to unicode."
authored
63 output = 'Provide either "url" or "feed" parameters!'
ae75674 @arantius Initial checkin, partially working.
authored
64
af2b102 @arantius Feed cleaning. Coerce everything to unicode.
authored
65 self.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
c4eebdc @arantius Send caching headers.
authored
66 self.response.headers['Cache-Control'] = 'max-age=3600'
91a33fe @arantius Syntax/lint clean ups.
authored
67 self.response.headers['Expires'] = email_utils.formatdate(
c4eebdc @arantius Send caching headers.
authored
68 timeval=time.time() + 3600, usegmt=True)
af2b102 @arantius Feed cleaning. Coerce everything to unicode.
authored
69 self.response.out.write(output)
ae75674 @arantius Initial checkin, partially working.
authored
70
15c860e @arantius util.Fetch() debug logging, whitespace fix
authored
71
ae75674 @arantius Initial checkin, partially working.
authored
72 def main():
73 application = webapp.WSGIApplication(
af2b102 @arantius Feed cleaning. Coerce everything to unicode.
authored
74 [('/', MainPage), ('/clean', Clean)],
5add88c @arantius Only check whether we're running in dev appserver once.
authored
75 debug=util.IS_DEV_APPSERVER)
ae75674 @arantius Initial checkin, partially working.
authored
76 run_wsgi_app(application)
77
78
79 if __name__ == '__main__':
80 main()
Something went wrong with that request. Please try again.