diff --git a/server.py b/server.py index 8b0c7d7..d90b022 100644 --- a/server.py +++ b/server.py @@ -14,7 +14,6 @@ app = Flask(__name__) def show(id): cursor.execute('SELECT * FROM meetings WHERE id=%s', [id]) result = cursor.fetchone() - print(result) return { "id":result[0], "num_participants":result[1], diff --git a/static/app.js b/static/app.js new file mode 100644 index 0000000..b58c744 --- /dev/null +++ b/static/app.js @@ -0,0 +1,25 @@ +const calculateMoneyLost = (data) => { + const start_seconds = new Date(data.start_time).getTime(); + const end_seconds = new Date().getTime(); + const difference = end_seconds-start_seconds; + + const microSecondlyPay = 100000/50/40/60/60/1000 + return microSecondlyPay*difference*data.num_participants; +} + +const getData = async () => { + const id = parseInt(window.location.pathname.split('/')[1]) + const response = await fetch('/meetings/'+id) + const data = await response.json(); + return data +} + +const main = async () => { + const data = await getData(); + const moneyLost = calculateMoneyLost(data) + document.querySelector('dd:nth-of-type(1)').innerHTML = data.num_participants + document.querySelector('dd:nth-of-type(2)').innerHTML = data.start_time + document.querySelector('dd:nth-of-type(3)').innerHTML = data.end_time ? data.end_time : 'Still losing money...' + document.querySelector('dd:nth-of-type(4)').innerHTML = moneyLost +} +setInterval(main,1000) diff --git a/templates/home.html b/templates/home.html index f48b70e..0158db6 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,10 +1,23 @@ -
- -