]>
jfr.im git - irc/rizon/acid.git/blob - pyva/src/main/python/erepublik/sys_news.py
3 from pseudoclient
.sys_base
import *
4 from api
import feed
, news
, region
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__
)
12 def parse(self
, message
):
17 last_update
= self
.get_option('last_timestamp', int, int(time
.time()))
19 cur_update
= int(time
.mktime(events
.updated
))
21 if cur_update
<= last_update
:
22 self
.set_option('last_timestamp', cur_update
)
27 for entry
in events
.entries
:
28 if int(time
.mktime(entry
['updated'])) > last_update
:
29 messages
.append(self
.parse(entry
['title']))
31 self
.set_option('last_timestamp', cur_update
)
33 self
.log
.warning("About to spam eRepublik News")
35 for channel
in self
.module
.channels
.list_valid():
37 self
.module
.multimsg(channel
.name
, 4, '@nsep @bNEWS@b @nsep ', ' @nsep ', messages
, ' @nsep')
38 except Exception, err
:
41 self
.module
.elog
.error('News broadcast failed: @b%s@b' % err
)