]> git.ipfire.org Git - ipfire.org.git/blame - www/webapp/datastore/banners.py
Create a global webapp database connection and create a config class.
[ipfire.org.git] / www / webapp / datastore / banners.py
CommitLineData
feb02477
MT
1#!/usr/bin/python
2
3import random
4import simplejson
5
6from tornado.database import Row
7
8class Banners(object):
9 def __init__(self, application, filename=None):
10 self.application = application
11 self.items = []
12
13 if filename:
14 self.load(filename)
15
16 def load(self, filename):
17 with open(filename) as f:
18 self.items = [Row(i) for i in simplejson.load(f)]
19
20 def get(self):
21 if self.items:
22 return random.choice(self.items)