-
-
Save alberto/384084 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import feedparser | |
import pynotify | |
import time | |
BASE_TITLE = 'Hudson Update!' | |
TIMEOUT = 3000 | |
def success(job, build): | |
n = pynotify.Notification(BASE_TITLE, | |
'"%s" %s successfully built :)' % (job, build), | |
'file:///usr/share/pixmaps/gnome-suse.png') | |
n.set_urgency(pynotify.URGENCY_LOW) | |
n.set_timeout(TIMEOUT) | |
return n | |
def unstable(job, build): | |
n = pynotify.Notification(BASE_TITLE, | |
'"%s" %s is unstable :-/' % (job, build), | |
'file:///usr/share/pixmaps/gnome-suse.png') | |
n.set_timeout(TIMEOUT) | |
return n | |
def failure(job, build): | |
n = pynotify.Notification(BASE_TITLE, | |
'"%s" %s failed!' % (job, build), | |
'file:///usr/share/pixmaps/gnome-suse.png') | |
n.set_urgency(pynotify.URGENCY_CRITICAL) | |
n.set_timeout(TIMEOUT) | |
return n | |
def main(): | |
pynotify.init('Hudson Notify') | |
last_displayed = {} | |
while True: | |
feed = feedparser.parse('http://localhost:8080/rssLatest') | |
items = [t['title'] for t in feed['entries']] | |
for i in items: | |
i = i.split(' ') | |
job, build, status = (i[0], i[1], i[2]) | |
if last_displayed.get(job) == (build, status): | |
continue | |
last_displayed[job] = (build, status) | |
status = status.replace('(', '').replace(')','') | |
if status == 'SUCCESS': | |
success(job, build).show() | |
elif status == 'UNSTABLE': | |
unstable(job, build).show() | |
elif status == 'FAILURE': | |
failure(job, build).show() | |
old_items = items | |
time.sleep(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment