laika.py 2.04 KB
import requests, json
from . import argentinidad, constructor

headers = {'Content-Type': 'application/json'}

class Laika:
    def __init__(self,url,user,passw,dev='Migrador') -> None:
        self.URL = f"https://{url}"
        self.APP = dev
        data = {
        'params':{'user':user,
                'pass':passw,
                'dev': self.APP},
                }
        data_json = json.dumps(data)
        r = requests.post(self.URL+ '/app/login', data=data_json, headers=headers)
        respuesta = r.json()
        self.LOGIN = respuesta['result']
        self.TOKEN = self.LOGIN['token']
        
    def CrearRegistro(self,modelo="",vals={}):
        data = {
                'params':{'token':self.TOKEN,
                'dev': self.APP},
                }
        data['params']['accion'] = 'create'
        data['params']['model'] = modelo
        data['params']['dominio'] = []
        data['params']['val'] = vals
        data_json = json.dumps(data)
        r = requests.post(self.URL +'/app/data', data=data_json, headers=headers)
        return(r.json()['result']['datos'])

    def BuscarDominio(self,modelo="",dominio=[]):
        data = {
                'params':{'token':self.TOKEN,
                'dev': self.APP},
                }
        data['params']['accion'] = 'search'
        data['params']['model'] = modelo
        data['params']['dominio'] = dominio
        data_json = json.dumps(data)
        r = requests.post(self.URL +'/app/data', data=data_json, headers=headers)
        return(r.json()['result']['datos'])

    def LeerDominio(self,modelo="",dominio=[],limit=0):
        data = {
                'params':{'token':self.TOKEN,
                'dev': self.APP},
                }
        data['params']['accion'] = 'read'
        data['params']['model'] = modelo
        data['params']['dominio'] = dominio
        if limit != 0:
            data['params']['limite'] = limit
        data_json = json.dumps(data)
        r = requests.post(self.URL +'/app/data', data=data_json, headers=headers)
        return(r.json()['result']['datos'])