-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.py
executable file
·33 lines (28 loc) · 1.53 KB
/
send.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
#!/usr/bin/env python3
"""
send.py
https://github.com/magnolialogic/python-apns_server
"""
import argparse
from APNSPushConnection import APNSPushConnection
def main():
"""
Sends APNS notification based on command-line arguments
"""
parser = argparse.ArgumentParser(description="Use APNS to send test push notifications to your iOS apps")
parser.add_argument("--prod", "--production", action="store_false", help="Use production environment")
parser.add_argument("--title", required=False, default="Title", help="Alert title text")
parser.add_argument("--body", required=False, default="Body", help="Alert body text")
parser.add_argument("--badge", type=int, required=False, default=0, help="Number to set in app icon badge")
parser.add_argument("--silent", action="store_true", help="Do not play sound")
parser.add_argument("--background", type=yaml.safe_load, required=False, help="Deliver quoted dict silently in background") # Pass a custom dictionary as background payload
#parser.add_argument("--background", type=int, required=False, help="Deliver Int data silently in the background")
parser.add_argument("--yaml", action="store_true", help="Use DeviceTokens from tokens.yaml instead of using APNS remote server API")
args = parser.parse_args()
session = APNSPushConnection(sandbox=args.prod, yaml_tokens=args.yaml)
session.create_payload(background=args.background, title=args.title, body=args.body, silent=args.silent, badge=args.badge)
session.push()
if __name__ == "__main__":
main()
else:
sys.exit("I am a script, do not import me.")