-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpush.py
26 lines (18 loc) · 822 Bytes
/
push.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
#!/usr/bin/env python
import httplib
import urllib
import datetime
class PushoverSender:
def __init__(self, user_key, api_key):
self.user_key = user_key
self.api_key = api_key
def send_notification(self, text):
now = datetime.datetime.now()
timestamp = "\n{:02}:{:02} on {:02}/{:02}/{:04}".format(
now.hour, now.minute, now.day, now.month, now.year)
text += timestamp
conn = httplib.HTTPSConnection("api.pushover.net:443")
post_data = {'user': self.user_key, 'token': self.api_key, 'message': text}
conn.request("POST", "/1/messages.json", urllib.urlencode(post_data), {"Content-type": "application/x-www-form-urlencoded"})
print("Push notification triggered at {:02}:{:02} on {:02}/{:02}/{:04}".format(now.hour, now.minute, now.day, now.month, now.year))
print(conn.getresponse().read())