This repository was archived by the owner on Nov 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjoincli.py
More file actions
49 lines (38 loc) · 1.58 KB
/
Copy pathjoincli.py
File metadata and controls
49 lines (38 loc) · 1.58 KB
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
import argparse
import json
import urllib.request
import urllib.parse
import os
import socket
import requests
def arguments():
ap = argparse.ArgumentParser()
ap.add_argument("-te", "--text", help="Text (Tasker Command or notification text)", nargs="*")
ap.add_argument("-ti", "--title", help="Title (If set will create notification)", nargs="*")
ap.add_argument("-mv", "--mediaVolume", help="Media Volume - number from 0 to 15", type=int, choices=range(0, 16))
ap.add_argument("-fi", "--find", help="Set to true to make your device ring loudly")
return vars(ap.parse_args())
def push_to_device(arguments,devices):
#print(arguments)
arguments["apikey"] = devices["apikey"]
arguments["deviceId"] = devices[devices["pref"]]["deviceId"]
encoded = []
for key, value in arguments.items():
if type(value) is list:
value = " ".join(value)
if value is not None:
encoded.append("=".join([key, str(value)]))
url = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?&"
print(encoded)
urllib.request.urlopen(url + "&".join(encoded).replace(" ","+")).read().decode("utf-8")
def devices():
try: # loads device json into a dictionary
with open("devices.json", "r") as device:
deviceData = json.loads(device.read())
except:
#TODO move into main and check for devices
os.system("python3 joincliSetup.py")
with open("devices.json", "r") as device:
deviceData = json.loads(device.read())
return deviceData
push_to_device(arguments(),devices())