-
Notifications
You must be signed in to change notification settings - Fork 1
/
feed.py
44 lines (35 loc) · 1.31 KB
/
feed.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
import cgi
from google.appengine.ext.webapp import template, RequestHandler, WSGIApplication
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import memcache
from google.appengine.ext import db
class Torrent(db.Model):
info_hash = db.StringProperty()
content = db.TextProperty()
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(RequestHandler):
def get(self, feed_type):
feed_cache=memcache.get(feed_type)
if feed_cache is None:
import os
torrents_query = Torrent.all().order('-date')
torrents = torrents_query.fetch(250)
template_values = {
'torrents': torrents,
}
if feed_type == 'rss':
path = os.path.join(os.path.dirname(__file__), 'rss.xml')
elif feed_type == 'txt':
path = os.path.join(os.path.dirname(__file__), 'feed.txt')
else:
path = os.path.join(os.path.dirname(__file__), 'feed.txt')
feed_cache=template.render(path, template_values)
memcache.set(feed_type, feed_cache)
self.response.out.write(feed_cache)
application = WSGIApplication([('/(rss).xml', MainPage),
('/(feed).txt', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()