Created
June 20, 2019 13:49
-
-
Save sourcerebels/dd6a5572739865c64befa95f223443f4 to your computer and use it in GitHub Desktop.
Albert test extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Edu test extension""" | |
from albertv0 import * | |
import urllib3 | |
import json | |
__iid__ = "PythonInterface/v0.1" | |
__prettyname__ = "MobileFinder" | |
__version__ = "0.1" | |
__trigger__ = "mobile " | |
__author__ = "Edu Rodríguez" | |
__dependencies__ = [] | |
# Request token at https://fonoapi.freshpixl.com/token/generate | |
FONO_API_TOKEN = "YOUR API KEY" | |
http = urllib3.PoolManager() | |
def handleQuery(query): | |
print("handleQuery") | |
if query.isTriggered: | |
print("handleQuery. query.isTriggered") | |
if query.string.strip(): | |
return locateDevices(query) | |
else: | |
return Item( | |
id=__prettyname__, | |
icon=iconLookup("phone"), | |
text=__prettyname__, | |
subtext="Type a mobile device name", | |
completion=query.rawString) | |
def locateDevices(query): | |
try: | |
print('locateDevices. start ' + query.string) | |
res = http.request("GET", "https://fonoapi.freshpixl.com/v1/getdevice", fields={'token': FONO_API_TOKEN, 'device': query.string, 'limit': 5}) | |
rjson = json.loads(res.data.decode('utf-8')) | |
print('locateDevices ' + str(rjson)) | |
print('locateDevices found ' + str(len(rjson))) | |
result = list(map(lambda device: Item( | |
id=device["DeviceName"], | |
icon=iconLookup("phone"), | |
text=device["DeviceName"], | |
subtext=device["Brand"], | |
completion=query.rawString), rjson)) | |
print('locateDevices result ' + str(len(result))) | |
return result; | |
except Exception as e: | |
print("Error " + str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment