[RssNotify] Display all commits, not just the latest one
parent
efe9b314c3
commit
9ff509de97
90
rssnotify.py
90
rssnotify.py
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
rssnotify.py - Phenny RssNotify Module
|
rssnotify.py - Phenny RssNotify Module
|
||||||
Copyright 2012, Sfan5
|
Copyright 2013, Sfan5
|
||||||
"""
|
"""
|
||||||
import feedparser, time, urllib # sudo easy_install feedparser
|
import feedparser, time, urllib, re # sudo easy_install feedparser
|
||||||
rssnotify = {}
|
rssnotify = {}
|
||||||
|
|
||||||
def get_arrayindex(array,val):
|
def get_arrayindex(array,val):
|
||||||
|
@ -12,14 +12,25 @@ def get_arrayindex(array,val):
|
||||||
return i
|
return i
|
||||||
return -1
|
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})")
|
||||||
|
g = reg.match(st).groups(1)
|
||||||
|
t = 0
|
||||||
|
t += int(g[5])
|
||||||
|
t += int(g[4]) * 60
|
||||||
|
t += int(g[3]) * 60 * 60
|
||||||
|
t += int(g[2]) * 60 * 60 * 24
|
||||||
|
t += int(g[1]) * 60 * 60 * 24 * 30
|
||||||
|
t += int(g[0]) * 60 * 60 * 24 * 30 * 12
|
||||||
|
return t
|
||||||
|
|
||||||
rssnotify["last_updated_feeds"] = {}
|
rssnotify["last_updated_feeds"] = {}
|
||||||
|
|
||||||
rssnotify["last_update"] = time.time()
|
|
||||||
rssnotify["dont_print_first_message"] = True
|
rssnotify["dont_print_first_message"] = True
|
||||||
rssnotify["update_cooldown"] = 60 # in seconds
|
rssnotify["update_cooldown"] = 60 # in seconds
|
||||||
rssnotify["show_commit_link"] = True
|
rssnotify["show_commit_link"] = True
|
||||||
rssnotify["use_git.io"] = True
|
rssnotify["use_git.io"] = True
|
||||||
|
rssnotify["last_update"] = time.time() - rssnotify["update_cooldown"]
|
||||||
|
|
||||||
|
|
||||||
def rsscheck(phenny, input):
|
def rsscheck(phenny, input):
|
||||||
|
@ -44,41 +55,42 @@ def rsscheck(phenny, input):
|
||||||
'referrer': 'http://minetest.net'
|
'referrer': 'http://minetest.net'
|
||||||
}
|
}
|
||||||
feed = feedparser.parse(url, **options)
|
feed = feedparser.parse(url, **options)
|
||||||
if len(feed.entries) == 0: continue
|
updcnt = 0
|
||||||
last_entry = feed.entries[0]
|
for feed_entry in feed.entries:
|
||||||
feednum = get_arrayindex(feeds,url)
|
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] != last_entry.updated:
|
if rssnotify["last_updated_feeds"][feednum] < to_unix_time(feed_entry.updated):
|
||||||
rssnotify["last_updated_feeds"][feednum] = last_entry.updated
|
commiter_realname = feed_entry.authors[0].name
|
||||||
commiter_realname = last_entry.authors[0].name
|
try:
|
||||||
try:
|
commiter = feed_entry.authors[0].href.replace('https://github.com/',"")
|
||||||
commiter = last_entry.authors[0].href.replace('https://github.com/',"")
|
except AttributeError:
|
||||||
except AttributeError:
|
commiter = commiter_realname # This will only print the Realname if the nickname couldn't be obtained
|
||||||
commiter = commiter_realname # This will only print the Realname if the nickname couldn't be obtained
|
reponame = url.replace("https://github.com/","").replace("/commits/master.atom","")
|
||||||
reponame = url.replace("https://github.com/","").replace("/commits/master.atom","")
|
commit_hash = feed_entry.links[0].href.replace("https://github.com/" + reponame + "/commit/","")[:10]
|
||||||
commit_hash = last_entry.links[0].href.replace("https://github.com/" + reponame + "/commit/","")[:10]
|
commit_time = feed_entry.updated
|
||||||
commit_time = last_entry.updated
|
updcnt += 1
|
||||||
print("[LOG]: Found RSS Update for URL '%s'" % (url))
|
if rssnotify["dont_print_first_message"]:
|
||||||
if rssnotify["dont_print_first_message"]:
|
continue # Don't print first Messages
|
||||||
continue # Don't print first Message
|
if rssnotify["show_commit_link"]:
|
||||||
if rssnotify["show_commit_link"]:
|
if rssnotify["use_git.io"]:
|
||||||
if rssnotify["use_git.io"]:
|
params = urllib.urlencode({'url' : feed_entry.link}) # git.io only works with *.github.com links
|
||||||
params = urllib.urlencode({'url' : last_entry.link}) # git.io only works with *.github.com links
|
u = urllib.urlopen("http://git.io/create", params)
|
||||||
u = urllib.urlopen("http://git.io/create", params)
|
commit_link = "http://git.io/" + u.read()
|
||||||
commit_link = "http://git.io/" + u.read()
|
else:
|
||||||
else:
|
commit_link = feed_entry.link
|
||||||
commit_link = last_entry.link
|
else:
|
||||||
else:
|
commit_link = ""
|
||||||
commit_link = ""
|
|
||||||
|
for ch in phenny.bot.channels:
|
||||||
for ch in phenny.bot.channels:
|
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,last_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, last_entry.title, commit_hash, commit_time, commit_link))
|
else:
|
||||||
else:
|
#phenny.say("GIT: %s commited to %s: %s %s %s" % (commiter,reponame,feed_entry.title,commit_hash,commit_time))
|
||||||
#phenny.say("GIT: %s commited to %s: %s %s %s" % (commiter,reponame,last_entry.title,commit_hash,commit_time))
|
phenny.write(['PRIVMSG', ch],"GIT: %s commited to %s: %s %s %s %s" % (commiter, reponame, feed_entry.title, commit_hash, commit_time, commit_link))
|
||||||
phenny.write(['PRIVMSG',ch],"GIT: %s commited to %s: %s %s %s %s" % (commiter, reponame, last_entry.title, commit_hash, commit_time, commit_link))
|
rssnotify["last_updated_feeds"][feednum] = to_unix_time(feed.entries[0].updated)
|
||||||
|
print("[LOG]: 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
|
||||||
|
|
Loading…
Reference in New Issue