-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.py
36 lines (31 loc) · 1.21 KB
/
notify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import fedmsg
from urlparse import urlparse
import requests
import pprint
from os.path import basename
import os
from gi.repository import Notify, GLib
Notify.init("Fedora Badges")
image_url = urlparse("https://badges.fedoraproject.org/pngs/tagger-02.png")
f = open("badges/"+basename(image_url.path),'wb')
f.write(requests.get('https://badges.fedoraproject.org/pngs/tagger-02.png').content)
f.close()
config = fedmsg.config.load_config([], None)
config['mute'] = True
config['timeout'] = 0
for name, endpoint, topic, msg in fedmsg.tail_messages(**config):
if topic.find("fedbadges.badge.award") > 0:
username = msg["msg"]["user"]["username"]
badgename = msg["msg"]["badge"]["name"]
image_url = msg["msg"]["badge"]["image_url"]
try:
filename = "badges/"+basename(urlparse(image_url).path)
except AttributeError:
pprint.pprint(msg)
f = open(filename,'wb')
f.write(requests.get(image_url).content)
f.close()
print username+ " got the "+badgename+" badge"
Hello=Notify.Notification.new (username+ " got the "+badgename+" badge",msg["msg"]["badge"]["description"],os.getcwd()+"/icon.png")
Notify.Notification.set_hint(Hello,"image-path", GLib.Variant.new_string(os.getcwd()+"/"+filename))
Hello.show()