]> jfr.im git - irc/rizon/acid.git/blob - pyva/src/main/python/erepublik/sys_news.py
Import acidictive 4 and pyva plugin
[irc/rizon/acid.git] / pyva / src / main / python / erepublik / sys_news.py
1 import time
2 import logging
3 from pseudoclient.sys_base import *
4 from api import feed, news, region
5
6 class NewsManager(Subsystem):
7 def __init__(self, module):
8 Subsystem.__init__(self, module, module.options, 'news')
9 self.set_option('last_timestamp', int(time.time()))
10 self.log = logging.getLogger(__name__)
11
12 def parse(self, message):
13 return message
14
15 def commit(self):
16 try:
17 last_update = self.get_option('last_timestamp', int, int(time.time()))
18 events = news.get()
19 cur_update = int(time.mktime(events.updated))
20
21 if cur_update <= last_update:
22 self.set_option('last_timestamp', cur_update)
23 return
24
25 messages = []
26
27 for entry in events.entries:
28 if int(time.mktime(entry['updated'])) > last_update:
29 messages.append(self.parse(entry['title']))
30
31 self.set_option('last_timestamp', cur_update)
32
33 self.log.warning("About to spam eRepublik News")
34
35 for channel in self.module.channels.list_valid():
36 if channel.news:
37 self.module.multimsg(channel.name, 4, '@nsep @bNEWS@b @nsep ', ' @nsep ', messages, ' @nsep')
38 except Exception, err:
39 import traceback
40 traceback.print_exc()
41 self.module.elog.error('News broadcast failed: @b%s@b' % err)