Beispiel #1
0
	def __init__(self):
		self.LATCH_INFO_PATH = "/usr/share/latch/latch-info.json"
		self.app_id = os.environ.get('LATCH_APP_ID', '')
		self.secret_key = os.environ.get('LATCH_SECRET_KEY', '')
		self.account_id = os.environ.get('LATCH_ACCOUNT_ID', '')
		self.api = latch.Latch(self.app_id, self.secret_key )

		self.refresco = os.environ.get('REFRESCO', '2')
Beispiel #2
0
 def __init__(self):
     #Lleno variables de configuración
     self.latchAux = Aux.OpenwrtLatchAux()
     self.APPID, self.SECRETKEY, self.TComprobacion = self.latchAux.cargar_config(
     )
     #self.SECRETKEY = self.latchAux.cargar_config("secretkey")
     self.api = latch.Latch(self.APPID, self.SECRETKEY)
     self.accountid = self.latchAux.cargar_accountid()
Beispiel #3
0
def main():
    AppId = ''
    #En esta seccion se debe colocar el AppId
    Secret = ''
    #En esta seccion se debe colocar el SecretID
    api = latch.Latch(AppId, Secret)
    token = sys.argv[1]
    response = api.pair(token)
    accountId = response.get_data().get('accountId')
    print accountId
Beispiel #4
0
 def init_app(self, app):
     app_id = app.config.get("LATCH_APP_ID", None)
     secret_key = app.config.get("LATCH_SECRET_KEY", None)
     if app_id is None:
         sys.stderr.write("LATCH_APP_ID configuration values is required")
     if secret_key is None:
         sys.stderr.write(
             "LATCH_SECRET_KEY configuration values is required")
     if app_id is not None and secret_key is not None:
         self.latch = latch.Latch(app_id, secret_key)
Beispiel #5
0
def latch_unpair(accountId):
    api = latch.Latch(config_data['appid'], config_data['seckey'])

    response = api.unpair(accountId)
    responseData = response.get_data()
    responseError = response.get_error()

    if responseError != "":
        logging.error("[latch_pair()] Error of unpaired:" + str(responseError))
        return 1
    else:
        return 0
Beispiel #6
0
def latchService():

    AppId = 'NnGdta7i36dqdetqnqHq'
    Secret = 'zLQxecyQxuuAkkNBjNr98kFjdmQs6uu8kgQXVz8y'
    accountId = 'crQbALnDd8mii3mrKy7nymHH8EUPQdE4UX9M83qUEFN93MewKxcQwzJkJ38CzdpX'

    api = latch.Latch(AppId, Secret)

    response = api.status(accountId)
    responseData = response.get_data()
    status = response.get_data().get('operations').get(AppId).get('status')

    return status
Beispiel #7
0
def latchService():

    AppId = ''
    Secret = ''
    accountId = getAccountId()

    if accountId == 'Cliente no registrado':
        print 'Debe registrar primero el dispositivo en nuestra pagina web con el codigo 91654917396765864'
        return 'Cliente no registrado'
    else:
        api = latch.Latch(AppId, Secret)
        response = api.status(accountId)
        responseData = response.get_data()
        status = response.get_data().get('operations').get(AppId).get('status')
        return status
Beispiel #8
0
def latch_status(accountId):
    api = latch.Latch(config_data['appid'], config_data['seckey'])
    response = api.status(accountId)
    responseData = response.get_data()
    responseError = response.get_error()
    if responseError != "" or responseData == "":
        logging.error("[latch_status()] Error of reload status:" +
                      str(responseError))
        return -1
    else:
        try:
            status = responseData['operations'][config_data['appid']]['status']
        except:
            status = "unknow"
        return status
Beispiel #9
0
def latch_pair():
    api = latch.Latch(config_data['appid'], config_data['seckey'])
    pair_code = raw_input("Enter pairing code: ")
    response = api.pair(pair_code)
    responseData = response.get_data()
    responseError = response.get_error()
    if responseError != "" or responseData == "":
        logging.error("[latch_pair()] Error of paired:" + str(responseError))
        return -1
    else:
        try:
            accountId = responseData.get('accountId')
        except (TypeError, ValueError, AttributeError) as err:
            logging.error("[latch_pair()] Error resolving JSON:" + str(err))
            return -1
        else:
            return accountId
Beispiel #10
0
    def __init__(self, *args, **kwargs):

        self.HCI_LESCAN_COMMAND = "hcitool lescan" # bluez command-line 
        self.HCI_RESTART_COMMAND = "hciconfig hci0 reset"
        self.LATCH_APP_ID = ''
        self.LATCH_APP_SECRET = ''

        self.TIMER_SCAN = 2 # time in seconds to scan devices
        self.MAX_RETRY_HCI = 3

        self.retry_hci_counter = 0
        self.list_tokens = []

        self.salt_hex = self.load_salt()
        self.hashed_mac = self.load_hashed_mac()

        self.api_latch = latch.Latch(self.LATCH_APP_ID, self.LATCH_APP_SECRET)
        self.latch_token = self.load_latch_token()

        if self.latch_token == None:
            self.latch_token = self.pair_latch_token() # ask for a latch pairing token

        if self.hashed_mac == None:
            self.hashed_mac = self.input_token_mac() # ask for a user MAC Address
Beispiel #11
0
import time, latch
from mechanize import Browser

# GMAIL SETTINGS
USER = '******'
PASSWD = 'YOUR_GMAIL_PASSWORD'

# LATCH SETTINGS
APP_ID = 'LATCH_APP_ID'
APP_SECRET = 'LATCH_APP_SECRET'
api = latch.Latch(APP_ID, APP_SECRET)

# Time beetwen auth checks in seconds
TIME = 3

# The AccountID we receive when we pair the device is saved in 'asd'.
# We read it, and if it has no content, we request the pairing code
f = open('account_id', 'r+')
accountId = f.read()
if (accountId == ''):
    print "Type your pairing code"
    pair_code = raw_input("> ")
    response = api.pair(pair_code)
    responseData = response.get_data()
    accountId = responseData["accountId"]
    f.write(accountId)
f.close()

# We use mechanize to enter in our gmail account
br = Browser()
br.set_handle_robots(False)
Beispiel #12
0
import latch

idcuenta = ""
estado = ""

appId = "PALPPPT7e7s4bfHmsidZ"

codigo = ""

api = latch.Latch(appId, "ZETW9jibcBFF2hq3yJVMb4upfBTm9TYzeeNBia32")

response = api.pair(codigo)
responseData = response.get_data()
if responseData["accountId"]:
    idcuenta = responseData["accountId"]
else:
    print "Error"
    print responseData

response = api.status(idcuenta)
responseData = response.get_data()
if responseData["operations"]:
    estado = responseData["operations"][appId]["status"]
else:
    print "error"

response = api.unpair(idcuenta)
Beispiel #13
0
def get_api(connect):
    configuration = get_db_latch(connect)
    return latch.Latch(configuration[0], configuration[1])
 def __init__(self):
     self.app_id = os.environ.get('LATCH_APP_ID', '')
     self.secret_key = os.environ.get('LATCH_SECRET_KEY', '')
     self.account_id = os.environ.get('LATCH_ACCOUNT_ID', '')
     self.api = latch.Latch(self.app_id, self.secret_key)
"""
----------------------------------------------------------------------------
                           Latch for OctoPrint
----------------------------------------------------------------------------
"""

## LIBRARIES ##
import re, sys
import latch

from config import *

## LATCH VARIABLES ##
# Imported from config file

api = latch.Latch(app_id, secret_key)


def pairLatch(pairingCode):
    response = api.pair(pairingCode)
    responseData = response.get_data()
    responseError = response.get_error()
    #print responseData
    account_add = re.findall(r"{u'accountId': u'(.*?)'}", str(responseData))
    if responseData:
        print 'Paired service'
        print 'Please, add the following account ID in the config file: ' + chr(
            27) + "[0;32m" + account_add[0] + chr(27) + "[0m"
    print responseError