-
Notifications
You must be signed in to change notification settings - Fork 0
/
gale.py
executable file
·73 lines (58 loc) · 2.08 KB
/
gale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
import os
import tornado.httpserver
import tornado.ioloop
import tornado.web
import datetime
import PyRSS2Gen
import sys
sys.path.append("providers")
from ArticleProvider import ArticleProvider
from PageProvider import PageProvider
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("templates/about.html", title="index")
class BlogHandler(tornado.web.RequestHandler):
def initialize(self):
self.a = ArticleProvider()
def get(self):
self.render("templates/index.html", title="index", items=self.a.parsed_list)
class RssHandler(tornado.web.RequestHandler):
def initialize(self):
self.a = ArticleProvider()
def get(self):
self.set_header("Content-Type", "application/rss+xml")
self.a.atom_dates()
self.render("templates/index.xml", title="unsure.org blog feed", url="http://unsure.org", author="Matthew Finlayson", email="[email protected]", items=self.a.parsed_list)
class ArticleHandler(tornado.web.RequestHandler):
def initialize(self):
self.a = ArticleProvider()
def get(self, new_url):
article = self.a.fetch_one(new_url)
if not article: raise tornado.web.HTTPError(404)
self.render("templates/article.html", title=article["title"], item=article)
class PageHandler(tornado.web.RequestHandler):
def initialize(self):
self.a = PageProvider()
def get(self, new_url):
page = self.a.fetch_one(new_url)
if not article: raise tornado.web.HTTPError(404)
self.render("templates/article.html", title=page["title"], item=page)
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static"),
"cookie_secret": "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
"login_url": "/login",
"xsrf_cookies": True,
}
application = tornado.web.Application([
(r"/", MainHandler),
(r"/blog/", BlogHandler),
(r"/blog/feed/", RssHandler),
(r"/about/", MainHandler),
(r"/projects/", MainHandler),
(r"/blog/([0-9]+/[0-9]+/[0-9]+/[-a-z0-9,]+/)", ArticleHandler),
], **settings)
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()