]> git.ipfire.org Git - ipfire.org.git/blob - www/webapp/datastore/news.py
Create a global webapp database connection and create a config class.
[ipfire.org.git] / www / webapp / datastore / news.py
1 #!/usr/bin/python
2
3 import simplejson
4
5 from tornado.database import Row
6
7 class News(object):
8 def __init__(self, application, filename=None):
9 self.application = application
10 self.items = []
11
12 if filename:
13 self.load(filename)
14
15 def load(self, filename):
16 f = open(filename)
17 data = f.read()
18 f.close()
19
20 data = data.replace("\n", "").replace("\t", " ")
21
22 json = simplejson.loads(data)
23 for key in sorted(json.keys()):
24 json[key]["id"] = key
25 self.items.append(Row(json[key]))
26
27 def get(self, limit=None):
28 ret = self.items[:]
29 ret.reverse()
30 if limit:
31 ret = ret[:limit]
32 return ret