Compare commits
6 Commits
603e6dba2b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ef3c1f4bfe | |||
|
|
f04bb3f69b | ||
|
|
139e11b5fc | ||
| ad26ef0196 | |||
| 5729cbe18a | |||
|
|
7a8ae86a1c |
14
deploy/Dockerfile
Normal file
14
deploy/Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
||||
FROM python:3.8
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY main.py .
|
||||
COPY static static
|
||||
COPY templates templates
|
||||
COPY deploy/presencia.ini .
|
||||
|
||||
CMD ["uwsgi", "--ini", "presencia.ini"]
|
||||
10
deploy/presencia.ini
Normal file
10
deploy/presencia.ini
Normal file
@@ -0,0 +1,10 @@
|
||||
[uwsgi]
|
||||
module = main:app
|
||||
chown = www-data:www-data
|
||||
uid = www-data
|
||||
gid = www-data
|
||||
chdir = /app/
|
||||
processes = 4
|
||||
threads = 2
|
||||
http = 0.0.0.0:5000
|
||||
wsgi-disable-file-wrapper = false
|
||||
9
deploy/publish.sh
Executable file
9
deploy/publish.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# BUILD
|
||||
docker build . -f deploy/Dockerfile -t presencia
|
||||
|
||||
# PUBLISH
|
||||
docker tag presencia marc.sastre.cat/presencia
|
||||
docker push marc.sastre.cat/presencia
|
||||
7
main.py
7
main.py
@@ -3,7 +3,7 @@ import re
|
||||
|
||||
import flask
|
||||
|
||||
text2bool = {"absència": True, "presència": False, "absent": True, "present": False}
|
||||
text2bool = {"absència": True, "absencia": True, "presencia": False, "presència": False, "absent": True, "present": False}
|
||||
bool2text = {True: "absent", False: "present"}
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
@@ -43,6 +43,11 @@ def calcula():
|
||||
return calcula_presencia(frase)
|
||||
|
||||
|
||||
@app.route("/static/<path:path>")
|
||||
def static_files(path):
|
||||
return flask.send_from_directory('static', path)
|
||||
|
||||
|
||||
def xor(a, b):
|
||||
return (a and not b) or (b and not a)
|
||||
|
||||
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Flask==2.0.2
|
||||
uwsgi==2.0.19.1
|
||||
@@ -0,0 +1,38 @@
|
||||
const r = (callback) => window.addEventListener('DOMContentLoaded', callback);
|
||||
const g = (name) => document.getElementById(name);
|
||||
|
||||
r(() => {
|
||||
g('submit').addEventListener('click', async () => {
|
||||
const frase = g('frase').value;
|
||||
const response = await fetch('/calcula', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
'frase': frase
|
||||
})
|
||||
})
|
||||
const resultat = await response.text();
|
||||
g('response').innerHTML = resultat;
|
||||
});
|
||||
|
||||
const afegirPart = (t) => {
|
||||
const frase = g('frase');
|
||||
let conector = ' de ';
|
||||
|
||||
if (frase.value === '') {
|
||||
conector = 'la ';
|
||||
}
|
||||
|
||||
g('frase').value = g('frase').value + conector + t;
|
||||
}
|
||||
|
||||
g('absencia').addEventListener('click', () => {
|
||||
afegirPart('absencia')
|
||||
});
|
||||
|
||||
g('presencia').addEventListener('click', () => {
|
||||
afegirPart('presencia')
|
||||
});
|
||||
})
|
||||
|
||||
23
static/style.css
Normal file
23
static/style.css
Normal file
@@ -0,0 +1,23 @@
|
||||
button {
|
||||
padding: 30px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#frase {
|
||||
width: 800px;
|
||||
height: 300px;
|
||||
text-align: center;
|
||||
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
#container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#buttons {
|
||||
padding: 50px;
|
||||
}
|
||||
@@ -1,11 +1,20 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Absencia de Presencia</title>
|
||||
<script src="/static/index.js"></script>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<form>
|
||||
<input type="text"/>
|
||||
<input type="submit"/>
|
||||
</form>
|
||||
<div id="container">
|
||||
<textarea id="frase"></textarea>
|
||||
|
||||
<div id="buttons">
|
||||
<button id="absencia">Absencia</button>
|
||||
<button id="presencia">Presencia</button>
|
||||
<button id="submit">Calcula</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="response"></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user