-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathdesktop_notifier.py
More file actions
54 lines (41 loc) · 1.46 KB
/
desktop_notifier.py
File metadata and controls
54 lines (41 loc) · 1.46 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# pip install and import the packages & modules
import feedparser
import notify2
import time
import os
from pygame import mixer
# initialize the mixer module
mixer.init()
# load the notification sound
mixer.music.load("alarm.mp3")
def Parsefeed():
# parsing news data from the feed URL
f = feedparser.parse("http://timesofindia.indiatimes.com/rssfeedstopstories.cms")
# set any icon for the notification
ICON_PATH = os.getcwd() + "/icon.ico"
# initalize the notify2 using init method and initializing the D-bus connection
notify2.init("News Notify")
# Looping from the parsed data to get the relevant information and setting the notification icon using notify2 lib
for newsitem in f["items"]:
print(newsitem["title"])
print(newsitem["summary"])
print("\n")
# create Notification object
n = notify2.Notification(newsitem["title"], newsitem["summary"], icon=ICON_PATH)
# set urgency level
n.set_urgency(notify2.URGENCY_NORMAL)
# show notification on screen
n.show()
# set timeout for a notification
n.set_timeout(100)
# short delay between notifications
time.sleep(10)
if __name__ == "__main__":
# call the functions
try:
Parsefeed()
mixer.music.play() # start producing sound while showing notification
time.sleep(10) # short delay
mixer.music.pause() # pause the sound
except:
print("Error")