laika.py
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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'])