Init
This commit is contained in:
commit
ed79985fba
5 changed files with 83 additions and 0 deletions
39
src/handler.py
Normal file
39
src/handler.py
Normal file
|
@ -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",
|
||||
},
|
||||
}
|
3
src/requirements.txt
Normal file
3
src/requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
beautifulsoup4==4.9.3
|
||||
numpy==1.20.1
|
||||
requests==2.25.1
|
Loading…
Add table
Add a link
Reference in a new issue