-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestpush.py
45 lines (34 loc) · 1.49 KB
/
testpush.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
#!/usr/bin/env python3
""" TestPush Module """
# -*- coding: utf-8 -*-
# =============================================================================
# Title : testpush.py
# Description : This script handles push notification testing
# Created By : Tim Owings
# Created Date : Jan 17, 2022
# Python : 3.9.2
# =============================================================================
import subprocess
import sys
import json
def push(token):
""" Send Push Notifications """
msg = "Hi Tim"
try:
# x = {"aps": {"alert": {"title": msg, "body": "WooHoo!"}, "sound": "Lucy-Im-home.aiff"}}
x = {"aps": {"alert": {"title": msg, "body": "WooHoo!"}, "sound": "houston-we-have-a-problem.aiff"}}
jsonMsg = json.dumps(x)
partUrl = "https://api.sandbox.push.apple.com/3/device/"
tokenUrl = partUrl + token
topic = "apns-topic: " + "com.javajoe.Home"
rc = subprocess.check_output(["curl", "-v", "--header", topic, "--header", "apns-push-type: alert",
"--cert", "/home/pi/sdr/PushCertificates.pem", "--key-type", "PEM", "--data", jsonMsg, "--http2", tokenUrl])
rc = rc.decode("utf-8")
if (rc):
print("push: call failed: rc = {}\n".format(rc))
else:
print("push: call was successful \n")
except Exception as e:
print("push: Exception is {}\n".format(e))
if __name__ == "__main__":
push(sys.argv[1])