[RssNotify] Allow sending Notify-Messages only to specific channels
Use [RssNotify] instead of [LOG] Clean up the Code a bitmaster
parent
28cfc9fa63
commit
62450d661b
45
rssnotify.py
45
rssnotify.py
|
@ -3,16 +3,11 @@
|
||||||
rssnotify.py - Phenny RssNotify Module
|
rssnotify.py - Phenny RssNotify Module
|
||||||
Copyright 2013, Sfan5
|
Copyright 2013, Sfan5
|
||||||
"""
|
"""
|
||||||
import feedparser, time, urllib, re # sudo easy_install feedparser
|
import time, urllib, re
|
||||||
|
import feedparser # sudo pip install feedparser
|
||||||
rssnotify = {}
|
rssnotify = {}
|
||||||
|
|
||||||
def get_arrayindex(array,val):
|
def to_unix_time(st): # not really accurate, but works
|
||||||
for i in range(0,len(array)):
|
|
||||||
if array[i] == val:
|
|
||||||
return i
|
|
||||||
return -1
|
|
||||||
|
|
||||||
def to_unix_time(st): # not really accurate
|
|
||||||
reg = re.compile("([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})")
|
reg = re.compile("([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})")
|
||||||
g = reg.match(st).groups(1)
|
g = reg.match(st).groups(1)
|
||||||
t = 0
|
t = 0
|
||||||
|
@ -38,18 +33,20 @@ def rsscheck(phenny, input):
|
||||||
if rssnotify["last_update"] > t-rssnotify["update_cooldown"]:
|
if rssnotify["last_update"] > t-rssnotify["update_cooldown"]:
|
||||||
return
|
return
|
||||||
rssnotify["last_update"] = t
|
rssnotify["last_update"] = t
|
||||||
print("[LOG]: Checking RSS Feeds...")
|
print("[RssNotify]: Checking RSS Feeds...")
|
||||||
start = time.time()
|
start = time.time()
|
||||||
feeds = [
|
feeds = [
|
||||||
'https://github.com/minetest/minetest/commits/master.atom',
|
('https://github.com/minetest/minetest/commits/master.atom', '*'),
|
||||||
'https://github.com/minetest/minetest_game/commits/master.atom',
|
('https://github.com/minetest/minetest_game/commits/master.atom', '*'),
|
||||||
'https://github.com/minetest/common/commits/master.atom',
|
('https://github.com/minetest/common/commits/master.atom', '*'),
|
||||||
'https://github.com/minetest/build/commits/master.atom',
|
('https://github.com/minetest/build/commits/master.atom', '*'),
|
||||||
'https://github.com/minetest/survival/commits/master.atom',
|
('https://github.com/minetest/survival/commits/master.atom', '*'),
|
||||||
'https://github.com/Uberi/MineTest-WorldEdit/commits/master.atom',
|
('https://github.com/Uberi/MineTest-WorldEdit/commits/master.atom', '*'),
|
||||||
'https://github.com/Jeija/minetest-mod-mesecons/commits/master.atom'
|
('https://github.com/Jeija/minetest-mod-mesecons/commits/master.atom' '*'),
|
||||||
]
|
]
|
||||||
for url in feeds:
|
for v in xrange(0, len(feeds)):
|
||||||
|
url = feeds[v][0]
|
||||||
|
feednum = v
|
||||||
options = {
|
options = {
|
||||||
'agent': 'Mozilla/5.0 (MinetestBot)',
|
'agent': 'Mozilla/5.0 (MinetestBot)',
|
||||||
'referrer': 'http://minetest.net'
|
'referrer': 'http://minetest.net'
|
||||||
|
@ -57,7 +54,6 @@ def rsscheck(phenny, input):
|
||||||
feed = feedparser.parse(url, **options)
|
feed = feedparser.parse(url, **options)
|
||||||
updcnt = 0
|
updcnt = 0
|
||||||
for feed_entry in feed.entries:
|
for feed_entry in feed.entries:
|
||||||
feednum = get_arrayindex(feeds, url)
|
|
||||||
if not feednum in rssnotify["last_updated_feeds"].keys():
|
if not feednum in rssnotify["last_updated_feeds"].keys():
|
||||||
rssnotify["last_updated_feeds"][feednum] = -1
|
rssnotify["last_updated_feeds"][feednum] = -1
|
||||||
if rssnotify["last_updated_feeds"][feednum] < to_unix_time(feed_entry.updated):
|
if rssnotify["last_updated_feeds"][feednum] < to_unix_time(feed_entry.updated):
|
||||||
|
@ -87,7 +83,14 @@ def rsscheck(phenny, input):
|
||||||
else:
|
else:
|
||||||
commit_link = ""
|
commit_link = ""
|
||||||
|
|
||||||
for ch in phenny.bot.channels:
|
chans = []
|
||||||
|
if feeds[v][1] == '*':
|
||||||
|
chans = phenny.bot.channels
|
||||||
|
elif type(feeds[v][1]) == type([]):
|
||||||
|
chans = feeds[v][1]
|
||||||
|
else:
|
||||||
|
print("[RssNotify]: Something went wrong!")
|
||||||
|
for ch in chans:
|
||||||
if commiter.lower() != commiter_realname.lower():
|
if commiter.lower() != commiter_realname.lower():
|
||||||
#phenny.say("GIT: %s (%s) commited to %s: %s %s %s" % (commiter,commiter_realname,reponame,feed_entry.title,commit_hash,commit_time))
|
#phenny.say("GIT: %s (%s) commited to %s: %s %s %s" % (commiter,commiter_realname,reponame,feed_entry.title,commit_hash,commit_time))
|
||||||
phenny.write(['PRIVMSG', ch],"GIT: %s (%s) commited to %s: %s %s %s %s" % (commiter, commiter_realname, reponame, feed_entry.title, commit_hash, commit_time, commit_link))
|
phenny.write(['PRIVMSG', ch],"GIT: %s (%s) commited to %s: %s %s %s %s" % (commiter, commiter_realname, reponame, feed_entry.title, commit_hash, commit_time, commit_link))
|
||||||
|
@ -101,11 +104,11 @@ def rsscheck(phenny, input):
|
||||||
m = to_unix_time(feed.entries[i].updated)
|
m = to_unix_time(feed.entries[i].updated)
|
||||||
rssnotify["last_updated_feeds"][feednum] = m
|
rssnotify["last_updated_feeds"][feednum] = m
|
||||||
if updcnt > 0:
|
if updcnt > 0:
|
||||||
print("[LOG]: Found %i RSS Update(s) for URL '%s'" % (updcnt, url))
|
print("[RssNotify]: Found %i RSS Update(s) for URL '%s'" % (updcnt, url))
|
||||||
end = time.time()
|
end = time.time()
|
||||||
if rssnotify["dont_print_first_message"]:
|
if rssnotify["dont_print_first_message"]:
|
||||||
rssnotify["dont_print_first_message"] = False
|
rssnotify["dont_print_first_message"] = False
|
||||||
print("[LOG]: Checked " + str(len(feeds)) + " RSS Feeds in %0.3f seconds" % (end-start))
|
print("[RssNotify]: Checked " + str(len(feeds)) + " RSS Feeds in %0.3f seconds" % (end-start))
|
||||||
|
|
||||||
rsscheck.priority = 'high'
|
rsscheck.priority = 'high'
|
||||||
rsscheck.rule = r'.*'
|
rsscheck.rule = r'.*'
|
||||||
|
|
Loading…
Reference in New Issue