Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pyjoin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Python API for using Join by joaoapps."""
import requests
from flask import request, Response, Flask
import os
import os
import json

SEND_URL = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?apikey="
LIST_URL = "https://joinjoaomgcd.appspot.com/_ah/api/registration/v1/listDevices?apikey="
Expand Down Expand Up @@ -74,8 +75,21 @@ def get_public_ip(self):

def get_devices(api_key):
response = requests.get(LIST_URL + api_key).json()

mypath = os.path.dirname(__file__)

if response.get('success') and not response.get('userAuthError'):
js = json.dumps([(r['deviceName'], r['deviceId']) for r in response['records']])
with open(mypath+'/'+api_key+'.json', 'w') as fh:
fh.write(js)
return [(r['deviceName'], r['deviceId']) for r in response['records']]
else:

if os.path.isfile(mypath+'/'+api_key+'.json'):
with open(mypath+'/'+api_key+'.json', 'r') as file:
s = file.read()
o = json.loads(s)
return o
return False

def send_notification(api_key, text, device_id=None, device_ids=None, device_names=None, title=None, icon=None, smallicon=None, vibration=None, image=None, url=None, tts=None, tts_language=None, sound=None, notification_id=None, category=None, actions=None):
Expand Down