diff --git a/pyjoin/__init__.py b/pyjoin/__init__.py index 7434761..aab85b5 100644 --- a/pyjoin/__init__.py +++ b/pyjoin/__init__.py @@ -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=" @@ -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):