]>
Commit | Line | Data |
---|---|---|
feb02477 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import random | |
4 | import simplejson | |
5 | ||
6 | from tornado.database import Row | |
7 | ||
8 | class 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) |