Spaces:
Runtime error
Runtime error
Moibe
commited on
Commit
•
f4e4dbc
1
Parent(s):
6d83a58
Add params var to each call
Browse files- app.py +4 -1
- sulkuPypi.py +32 -5
app.py
CHANGED
@@ -54,7 +54,10 @@ def perform(input1, input2, request: gr.Request):
|
|
54 |
|
55 |
def display_tokens(request: gr.Request):
|
56 |
|
57 |
-
|
|
|
|
|
|
|
58 |
tokens = sulkuPypi.getTokens(sulkuPypi.encripta(request.username).decode("utf-8"))
|
59 |
display = tools.actualizar_creditos(tokens, request.username)
|
60 |
|
|
|
54 |
|
55 |
def display_tokens(request: gr.Request):
|
56 |
|
57 |
+
#Para desplegar o no desplegar, necesitamos saber si el usuario es new user.
|
58 |
+
flag = sulkuPypi.getFlag(request.username)
|
59 |
+
print("La flag obtenida es: ", flag)
|
60 |
+
|
61 |
tokens = sulkuPypi.getTokens(sulkuPypi.encripta(request.username).decode("utf-8"))
|
62 |
display = tools.actualizar_creditos(tokens, request.username)
|
63 |
|
sulkuPypi.py
CHANGED
@@ -12,7 +12,7 @@ userfile = "gAAAAABmEZA4SLBC2YczouOrjIEi9WNCNGOIvyUcqBUnzxNsftXTdy54KaX9x8mAjFkA
|
|
12 |
#... con el símbolo =, ? y &. Dicho problema solo sucede cuando lo recibe como query params no como path params.
|
13 |
work = "picswap"
|
14 |
|
15 |
-
#Todas son llamadas a la API, excepto
|
16 |
#lo que le vas a enviar a la API.
|
17 |
def encripta(username):
|
18 |
|
@@ -32,6 +32,7 @@ def encripta(username):
|
|
32 |
def getData():
|
33 |
|
34 |
method = "getData/"
|
|
|
35 |
api_url = base_url + method
|
36 |
response = requests.get(api_url)
|
37 |
|
@@ -45,10 +46,30 @@ def getData():
|
|
45 |
|
46 |
return data
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def getTokens(userfile):
|
49 |
|
50 |
method = "getTokens/"
|
51 |
-
|
|
|
|
|
52 |
response = requests.get(api_url)
|
53 |
|
54 |
if response.status_code == 200:
|
@@ -63,7 +84,9 @@ def getTokens(userfile):
|
|
63 |
def authorize(tokens, work):
|
64 |
|
65 |
method = "authorize/"
|
66 |
-
|
|
|
|
|
67 |
response = requests.get(api_url)
|
68 |
|
69 |
if response.status_code == 200:
|
@@ -78,7 +101,9 @@ def authorize(tokens, work):
|
|
78 |
def debitTokens(userfile, work):
|
79 |
|
80 |
method = "debitTokens/"
|
81 |
-
|
|
|
|
|
82 |
response = requests.get(api_url)
|
83 |
|
84 |
if response.status_code == 200:
|
@@ -95,7 +120,9 @@ def debitTokensQ(userfile, work):
|
|
95 |
#debitTokens pero con QueryParams, (los query params sirve para ocasiones en los que usas dos de un mismo query param para abtener el resultado de un AND o rangos como...
|
96 |
#... clima por ejemplo.)
|
97 |
method = "debitTokens?"
|
98 |
-
|
|
|
|
|
99 |
response = requests.get(api_url)
|
100 |
|
101 |
if response.status_code == 200:
|
|
|
12 |
#... con el símbolo =, ? y &. Dicho problema solo sucede cuando lo recibe como query params no como path params.
|
13 |
work = "picswap"
|
14 |
|
15 |
+
#Todas son llamadas a la API, excepto encripta, que es una herramienta para prepara precisamente, ...
|
16 |
#lo que le vas a enviar a la API.
|
17 |
def encripta(username):
|
18 |
|
|
|
32 |
def getData():
|
33 |
|
34 |
method = "getData/"
|
35 |
+
|
36 |
api_url = base_url + method
|
37 |
response = requests.get(api_url)
|
38 |
|
|
|
46 |
|
47 |
return data
|
48 |
|
49 |
+
def getFlag(userfile):
|
50 |
+
|
51 |
+
method = "getUserFlag/"
|
52 |
+
params = userfile
|
53 |
+
|
54 |
+
api_url = base_url + method + params
|
55 |
+
response = requests.get(api_url)
|
56 |
+
|
57 |
+
if response.status_code == 200:
|
58 |
+
print("Conexión a Sulku successful...")
|
59 |
+
flag = response.json()
|
60 |
+
#IMPORTANTE: Aquí se obtuvo la lista completa de accesos.
|
61 |
+
#Future, se puede optimizar eso en cuanto a seguridad?
|
62 |
+
else:
|
63 |
+
print("Error al obtener el elemento todo:", response.status_code)
|
64 |
+
|
65 |
+
return flag
|
66 |
+
|
67 |
def getTokens(userfile):
|
68 |
|
69 |
method = "getTokens/"
|
70 |
+
params = userfile
|
71 |
+
|
72 |
+
api_url = base_url + method + params
|
73 |
response = requests.get(api_url)
|
74 |
|
75 |
if response.status_code == 200:
|
|
|
84 |
def authorize(tokens, work):
|
85 |
|
86 |
method = "authorize/"
|
87 |
+
params = str(tokens) + "/" + work
|
88 |
+
|
89 |
+
api_url = base_url + method + params
|
90 |
response = requests.get(api_url)
|
91 |
|
92 |
if response.status_code == 200:
|
|
|
101 |
def debitTokens(userfile, work):
|
102 |
|
103 |
method = "debitTokens/"
|
104 |
+
params = userfile + "/" + work
|
105 |
+
|
106 |
+
api_url = base_url + method + params
|
107 |
response = requests.get(api_url)
|
108 |
|
109 |
if response.status_code == 200:
|
|
|
120 |
#debitTokens pero con QueryParams, (los query params sirve para ocasiones en los que usas dos de un mismo query param para abtener el resultado de un AND o rangos como...
|
121 |
#... clima por ejemplo.)
|
122 |
method = "debitTokens?"
|
123 |
+
params = "userfile=" + userfile + "&" + "work=" + work
|
124 |
+
|
125 |
+
api_url = base_url + method + params
|
126 |
response = requests.get(api_url)
|
127 |
|
128 |
if response.status_code == 200:
|