[rssnotify] Update and fix a few things
parent
5fd4be8693
commit
6eee4e7567
35
rssnotify.py
35
rssnotify.py
|
@ -47,6 +47,7 @@ def resolve_channels(phenny, l):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
class RssNotify():
|
class RssNotify():
|
||||||
|
MAX_MESSAGES = 6
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.last_updated = {}
|
self.last_updated = {}
|
||||||
|
@ -61,26 +62,30 @@ class RssNotify():
|
||||||
print("[RssNotify]: Checking RSS feeds...")
|
print("[RssNotify]: Checking RSS feeds...")
|
||||||
for fid, feedspec in enumerate(self.config["feeds"]):
|
for fid, feedspec in enumerate(self.config["feeds"]):
|
||||||
feed = feedparser.parse(feedspec[0], agent="Mozilla/5.0 (compatible; MinetestBot)")
|
feed = feedparser.parse(feedspec[0], agent="Mozilla/5.0 (compatible; MinetestBot)")
|
||||||
updated = 0
|
|
||||||
for entry in feed.entries:
|
|
||||||
if self.firstrun:
|
if self.firstrun:
|
||||||
break
|
self.last_updated[fid] = max((to_unix_time(e.updated) for e in feed.entries), default=0)
|
||||||
|
continue
|
||||||
|
new = []
|
||||||
|
for entry in feed.entries:
|
||||||
if self.last_updated[fid] >= to_unix_time(entry.updated):
|
if self.last_updated[fid] >= to_unix_time(entry.updated):
|
||||||
continue
|
continue
|
||||||
message = self._format_msg(entry)
|
new.append(entry)
|
||||||
self._announce(phenny, message, feedspec[1])
|
if len(new) == 0:
|
||||||
|
continue
|
||||||
|
print("[RssNotify]: Found %d update(s) for '%s'" % (len(new), feedspec[0]))
|
||||||
|
self.last_updated[fid] = max(to_unix_time(e.updated) for e in feed.entries)
|
||||||
|
new.reverse()
|
||||||
if self.config["logfile"] is not None:
|
if self.config["logfile"] is not None:
|
||||||
with open(self.config["logfile"], "a", encoding="utf-8") as f:
|
with open(self.config["logfile"], "a", encoding="utf-8") as f:
|
||||||
|
for entry in new:
|
||||||
message = self._format_msg(entry, log_format=True)
|
message = self._format_msg(entry, log_format=True)
|
||||||
f.write(message)
|
f.write(message + "\n")
|
||||||
f.write("\n")
|
for entry in new[:RssNotify.MAX_MESSAGES]:
|
||||||
updated += 1
|
message = self._format_msg(entry)
|
||||||
new_time = max((to_unix_time(e.updated) for e in feed.entries), default=0)
|
self._announce(phenny, message, feedspec[1])
|
||||||
if new_time > self.last_updated[fid]:
|
if len(new) > RssNotify.MAX_MESSAGES:
|
||||||
self.last_updated[fid] = new_time
|
message = self._get_cutoff_message(len(new) - RssNotify.MAX_MESSAGES)
|
||||||
if updated > 0:
|
self._announce(phenny, message, feedspec[1])
|
||||||
print("[RssNotify]: Found %d update(s) for '%s'" % (updated, feedspec[0]))
|
|
||||||
if self.firstrun:
|
|
||||||
self.firstrun = False
|
self.firstrun = False
|
||||||
print("[RssNotify]: Checked %d RSS feeds in %0.3f seconds" % (len(self.config["feeds"]), time.time()-start))
|
print("[RssNotify]: Checked %d RSS feeds in %0.3f seconds" % (len(self.config["feeds"]), time.time()-start))
|
||||||
def _shorten(self, link):
|
def _shorten(self, link):
|
||||||
|
@ -127,6 +132,8 @@ class RssNotify():
|
||||||
else:
|
else:
|
||||||
committer_final = f_clong % (committer, committer_realname)
|
committer_final = f_clong % (committer, committer_realname)
|
||||||
return f_all % (committer_final, repo_name, commit_text, commit_hash, commit_link, commit_time)
|
return f_all % (committer_final, repo_name, commit_text, commit_hash, commit_link, commit_time)
|
||||||
|
def _get_cutoff_message(self, left):
|
||||||
|
return "\x0302[git]\x0f (%d newer commits not shown)" % left
|
||||||
def _announce(self, phenny, message, chans):
|
def _announce(self, phenny, message, chans):
|
||||||
chans = resolve_channels(phenny, chans)
|
chans = resolve_channels(phenny, chans)
|
||||||
for ch in chans:
|
for ch in chans:
|
||||||
|
|
Loading…
Reference in New Issue