Compare commits

...

2 Commits

Author SHA1 Message Date
Roberto Alsina 21abfbfd98 Reorg repo 2023-05-16 12:38:37 -03:00
Roberto Alsina f775068850 New service 2023-05-16 12:35:02 -03:00
20 changed files with 107 additions and 7 deletions

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# Cosas hechas con FAAS
Para hacer el deploy obviamente necesita acceso a pass para conectarse con faasd
y mi VPN y mis credenciales y un monton de cosas que solo tengo yo, espero :-)
En particular faas-cli (ver scripts build.sh y deploy.sh) necesita docker con buildx
## busqueda / historico
Funciones para hacer cosas con la data de nombres de Argentina.
Página con esto funcionando: http://nombres.ralsina.me
## tapas
Funcion para generar tapas de libros
Página con esto funcionando: http://covers.ralsina.me

View File

@ -11,3 +11,7 @@ functions:
lang: python3-flask
handler: ./historico
image: ralsina/nombres_historico:latest
tapas:
lang: python3-flask
handler: ./tapas
image: ralsina/tapas:latest

View File

@ -1,7 +0,0 @@
Scripts para hacer cosas con la data de nombres de Argentina.
Página con esto funcionando: http://nombres.ralsina.me
* historico/ y busqueda/ son funciones OpenFAAS para implementar el sitio
* faas-cli (ver scripts build.sh y deploy.sh) necesita docker con buildx
* Para hacer el deploy obviamente necesita acceso a pass para conectarse con faasd

0
tapas/__init__.py Normal file
View File

32
tapas/handler.py Normal file
View File

@ -0,0 +1,32 @@
from json import loads
from tapita import Cover
from io import BytesIO
import base64
def handle(req):
"""handle a request to the function
Args:
req (str): request body
{
"title": "foo",
"subtitle": "bar",
"author": "bat",
}
"""
try:
args = loads(req)
except Exception:
return "Bad Request", 400
c = Cover(**args)
byte_arr = BytesIO()
c.image.save(byte_arr, format="JPEG")
# return Response(chart.render(is_unicode=True), mimetype="image/svg+xml")
return (
f'<img src="data:image/jpeg;base64, {base64.b64encode(byte_arr.getvalue()).decode("utf-8")}">',
200,
{"Content-Type": "text/html"},
)

11
tapas/handler_test.py Normal file
View File

@ -0,0 +1,11 @@
from .handler import handle
# Test your handler here
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
def test_handle():
# assert handle("input") == "input"
pass

1
tapas/requirements.txt Normal file
View File

@ -0,0 +1 @@
tapita

41
tapas/tox.ini Normal file
View File

@ -0,0 +1,41 @@
# If you would like to disable
# automated testing during faas-cli build,
# Replace the content of this file with
# [tox]
# skipsdist = true
# You can also edit, remove, or add additional test steps
# by editing, removing, or adding new testenv sections
# find out more about tox: https://tox.readthedocs.io/en/latest/
[tox]
envlist = lint,test
skipsdist = true
[testenv:test]
deps =
flask
pytest
-rrequirements.txt
commands =
# run unit tests with pytest
# https://docs.pytest.org/en/stable/
# configure by adding a pytest.ini to your handler
pytest
[testenv:lint]
deps =
flake8
commands =
flake8 .
[flake8]
count = true
max-line-length = 127
max-complexity = 10
statistics = true
# stop the build if there are Python syntax errors or undefined names
select = E9,F63,F7,F82
show-source = true