commit ed79985fbad786ae95ccd1d23b64c1263fa6e64d Author: Tobias Reisinger Date: Fri Mar 5 01:12:34 2021 +0100 Init diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..5ee3080 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,30 @@ +kind: pipeline +name: default + +steps: +- name: generate + image: knovus/drone-openfaas + settings: + template: python3-http + +- name: build + image: plugins/docker + settings: + username: + from_secret: docker_registry_user + password: + from_secret: docker_registry_pass + registry: registry.serguzim.me + repo: registry.serguzim.me/faas/${DRONE_REPO_NAME} + context: ./build/${DRONE_REPO_NAME}/ + dockerfile: ./build/${DRONE_REPO_NAME}/Dockerfile + tags: latest + +- name: deploy + image: knovus/drone-openfaas + settings: + deploy: true + url: https://faas.serguzim.me + password: + from_secret: openfaas_password + registry: registry.serguzim.me diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fda848 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +template/ diff --git a/src/handler.py b/src/handler.py new file mode 100644 index 0000000..075d7d7 --- /dev/null +++ b/src/handler.py @@ -0,0 +1,39 @@ +from bs4 import BeautifulSoup +import numpy as np +import requests + +def handle(event, context): + + page = requests.get('https://courses.wiso.uni-tuebingen.de/matrix/matrix-of-the-day') + + soup = BeautifulSoup(page.text, 'html.parser') + + matrix_tag = soup.find_all('div', class_='matrix')[0].contents + matrix_msg = matrix_tag[1].contents[0] + matrix_split = matrix_tag[2].split('\n') + + while '' in matrix_split: + matrix_split.remove('') + + for i in range(len(matrix_split)): + char = matrix_split[i] + if char == '&': + matrix_split[i] = ' ' + if char == '\\\\': + matrix_split[i] = ';' + + a = np.matrix(''.join(matrix_split[1:-1]).rstrip(';')) + + result = {} + + result['message'] = matrix_msg + result['matrix'] = str(a) + result['determinant'] = np.linalg.det(a) + + return { + "statusCode": 200, + "body": result, + "headers": { + "content-type": "application/json", + }, + } diff --git a/src/requirements.txt b/src/requirements.txt new file mode 100644 index 0000000..1e43eae --- /dev/null +++ b/src/requirements.txt @@ -0,0 +1,3 @@ +beautifulsoup4==4.9.3 +numpy==1.20.1 +requests==2.25.1 diff --git a/stack.yml b/stack.yml new file mode 100644 index 0000000..f97f486 --- /dev/null +++ b/stack.yml @@ -0,0 +1,9 @@ +provider: + name: openfaas + gateway: https://faas.serguzim.me + +functions: + determinant-of-the-day: + lang: python3-http + handler: ./src + image: registry.serguzim.me/faas/determinant-of-the-day