def subscription_type(uuid=""): sub_type = "free" device = DEVICES.get_device_by_uuid(uuid) if device is not None: sub_type = device.subscription subscription = {"@type": sub_type} return nice_json(subscription)
def get_subscriber_voice_url(uuid=""): arch = request.args["arch"] device = DEVICES.get_device_by_uuid(uuid) if device is not None: device.arch = arch DEVICES.commit() return nice_json({"link": ""})
def metric(uuid="", name=""): data = request.json print name, data device = DEVICES.get_device_by_uuid(uuid) if device is None: return DEVICES.add_metric(name=name, uuid=uuid, data=data)
def get_uuid(uuid): device = DEVICES.get_device_by_uuid(uuid) if device is not None: if request.method == 'PATCH': result = request.json DEVICES.add_device(uuid=uuid, name=result.get("name"), expires_at=result.get("expires_at"), accessToken=result.get("accessToken"), refreshToken=result.get("refreshToken")) result = model_to_dict(device) else: result = {} return nice_json(result)
def get_uuid(uuid): device = DEVICES.get_device_by_uuid(uuid) if device is not None: if request.method == 'PATCH': result = request.json print result DEVICES.patch_device( uuid=uuid, coreVersion=result.get("coreVersion"), platform=result.get("platform"), platform_build=result.get("platform_build"), enclosureVersion=result.get("enclosureVersion")) result = model_to_dict(device) else: result = {} return nice_json(result)
def activate(): uuid = request.json["state"] # paired? device = DEVICES.get_device_by_uuid(uuid) if device is None or not device.paired: return Response( 'Could not verify your access level for that URL.\n' 'You have to authenticate with proper credentials', 401, {'WWW-Authenticate': 'Basic realm="NOT PAIRED"'}) # generate access tokens DEVICES.add_device(uuid=uuid, expires_at=time.time() + 72000, accessToken=gen_api(), refreshToken=gen_api()) result = model_to_dict(device) return nice_json(result)
def location(uuid): device = DEVICES.get_device_by_uuid(uuid) if device is None: return nice_json({"error": "device not found"}) if device.location.timezone is None: if not request.headers.getlist("X-Forwarded-For"): ip = request.remote_addr else: # TODO http://esd.io/blog/flask-apps-heroku-real-ip-spoofing.html ip = request.headers.getlist("X-Forwarded-For")[0] DEVICES.add_ip(uuid, ip) new_location = geo_locate(ip) DEVICES.add_location(uuid, new_location) return nice_json(new_location) location = device.location result = location_dict(location.city, location.region_code, location.country_code, location.country_name, location.region, location.longitude, location.latitude, location.timezone) return nice_json(result)
def setting(uuid=""): device = DEVICES.get_device_by_uuid(uuid) if device is not None: result = model_to_dict(device.config) # format results # skills cleans = ["skills_dir", "skills_auto_update", "device_id", "id"] blacklisted = [ skill.folder for skill in device.config.skills if skill.blacklisted ] priority = [ skill.folder for skill in device.config.skills if skill.priority ] result["skills"] = { "directory": device.config.skills_dir, "auto_update": device.config.skills_auto_update, "blacklisted_skills": blacklisted, "priority_skills": priority } # location location = device.location result["location"] = location_dict(location.city, location.region_code, location.country_code, location.country_name, location.region, location.longitude, location.latitude, location.timezone) # listener cleans += [ "listener_energy_ratio", "record_wake_words", "record_utterances", "wake_word_upload", "stand_up_word", "wake_word", "listener_sample_rate", "listener_channels", "listener_multiplier", "phoneme_duration" ] result["listener"] = { "sample_rate": result["listener_sample_rate"], "channels": result["listener_channels"], "record_wake_words": result["record_wake_words"], "record_utterances": result["record_utterances"], "phoneme_duration": result["phoneme_duration"], "wake_word_upload": { "enable": result["wake_word_upload"] }, "multiplier": result["listener_multiplier"], "energy_ratio": result["listener_energy_ratio"], "wake_word": result["wake_word"], "stand_up_word": result["stand_up_word"] } # sounds result["sounds"] = {} for sound in device.config.sounds: result["sounds"][sound.name] = sound.path # hotwords result["hotwords"] = {} for word in device.config.hotwords: result["hotwords"][word.name] = { "module": word.module, "phonemes": word.phonemes, "threshold": word.threshold, "lang": word.lang, "active": word.active, "listen": word.listen, "utterance": word.utterance, "sound": word.sound } # stt stt = device.config.stt creds = {} if stt.engine_type == "token": creds = {"token": stt.token} elif stt.engine_type == "basic": creds = {"username": stt.username, "password": stt.password} elif stt.engine_type == "key": creds = {"client_id": stt.client_id, "client_key": stt.client_key} elif stt.engine_type == "json": creds = {"json": stt.client_id, "client_key": stt.client_key} result["stt"] = { "module": stt.name, stt.name: { "uri": stt.uri, "lang": stt.lang, "credential": creds } } # tts tts = device.config.tts result["tts"] = { "module": tts.name, tts.name: { "token": tts.token, "lang": tts.lang, "voice": tts.voice, "gender": tts.gender, "uri": tts.uri } } if tts.engine_type == "token": result["tts"][tts.name].merge({"token": tts.token}) elif tts.engine_type == "basic": result["tts"][tts.name].merge({ "username": tts.username, "password": tts.password }) elif tts.engine_type == "key": result["tts"][tts.name].merge({ "client_id": tts.client_id, "client_key": tts.client_key }) elif tts.engine_type == "api": result["tts"][tts.name].merge({"api_key": tts.api_key}) for c in cleans: result.pop(c) else: result = {} return nice_json(result)