update main
Browse files- api/main.py +17 -2
api/main.py
CHANGED
@@ -1,7 +1,22 @@
|
|
1 |
from api.core.app import Demos
|
2 |
__main = Demos()
|
3 |
api = __main.api()
|
4 |
-
@api.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def get_text_from_url(data:dict) -> dict:
|
6 |
__response=dict({"request_data":data})
|
7 |
try:
|
@@ -12,6 +27,6 @@ def get_text_from_url(data:dict) -> dict:
|
|
12 |
except Exception as e:
|
13 |
print(e)
|
14 |
#To-do ->agregar mas información en el error fecha, usuario, reqs
|
15 |
-
raise __main.exception(status_code =
|
16 |
finally:
|
17 |
return __response
|
|
|
1 |
from api.core.app import Demos
|
2 |
__main = Demos()
|
3 |
api = __main.api()
|
4 |
+
@api.get("/", status_code=201)
|
5 |
+
def home(data:dict) -> dict:
|
6 |
+
__response=dict({"request_data":data})
|
7 |
+
try:
|
8 |
+
if data:
|
9 |
+
__response['texto']=__main.obtener_texto(from_url=data.get('url'))
|
10 |
+
else:
|
11 |
+
raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
|
12 |
+
except Exception as e:
|
13 |
+
print(e)
|
14 |
+
#To-do ->agregar mas información en el error fecha, usuario, reqs
|
15 |
+
raise __main.exception(status_code = 403, datail=e)
|
16 |
+
finally:
|
17 |
+
return __response
|
18 |
+
|
19 |
+
@api.post("/obtener_texto/", status_code=201)
|
20 |
def get_text_from_url(data:dict) -> dict:
|
21 |
__response=dict({"request_data":data})
|
22 |
try:
|
|
|
27 |
except Exception as e:
|
28 |
print(e)
|
29 |
#To-do ->agregar mas información en el error fecha, usuario, reqs
|
30 |
+
raise __main.exception(status_code = 403, datail=e)
|
31 |
finally:
|
32 |
return __response
|