-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.py
67 lines (48 loc) · 1.59 KB
/
notification.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Placement Notifier for Linux and android/ios"""
import feedparser
import notify2
import time
import os
import urllib
import base64
MOBILE_NOTIFICATION = True
if MOBILE_NOTIFICATION:
from notify_run import Notify
def Parsefeed():
ICON_PATH = os.getcwd() + "/64x64.png"
url = "placements.iitb.ac.in"
if MOBILE_NOTIFICATION:
notify = Notify()
#ldap ID
auth_user = ""
#ldap Password
auth_passwd = ""
#Securing your HTTP request
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, url, auth_user, auth_passwd)
authhandler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(authhandler)
urllib.request.install_opener(opener)
notify2.init('Placement Blog Notify')
old =None
while(1):
response = urllib.request.urlopen("http://placements.iitb.ac.in/blog/?feed=rss2").read()
f = feedparser.parse(response)
new = f['items'][0]['title'].encode('utf-8')
if new != old:
n = notify2.Notification(f['items'][0]['title'].encode('utf-8'),
f['items'][0]['summary'].encode('utf-8'),
icon=ICON_PATH
)
n.set_urgency(notify2.URGENCY_NORMAL)
n.show()
if MOBILE_NOTIFICATION:
notify.send(new)
old = new
n.set_timeout(15000)
time.sleep(3000)
if __name__ == '__main__':
try:
Parsefeed()
except:
print("Error")