-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpushsafer.py
More file actions
27 lines (21 loc) · 787 Bytes
/
pushsafer.py
File metadata and controls
27 lines (21 loc) · 787 Bytes
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
# (c) stonatm@gmail.com
# micropython pushsafer notification sender
import urequests
import json
DEBUG = False
def send_notification(private_key, device, title, message, sound, vibration, icon ):
# create rest api request
url = 'https://www.pushsafer.com/api'
url = url + '?k=' + str(private_key) + '&d=' + str(device) + '&t=' + str(title.replace(' ','%20')) + '&m=' + str(message.replace(' ','%20')) +'&s=' +str(sound) + "&v=" + str(vibration) + "&i=" + str(icon)
# rest api call
response = urequests.post(url = url)
# debug
if DEBUG:
print('response text:')
print(response.text)
# convert response to json
if 'status' in response.content.decode():
json_encoded = json.loads(response.content)
return json_encoded['status']
else:
return 0