You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
865 B
33 lines
865 B
from flask import Flask, request, render_template
|
|
import mysql.connector
|
|
|
|
mydb = mysql.connector.connect(
|
|
database="time_wasted",
|
|
user="root"
|
|
)
|
|
mydb.autocommit = True
|
|
cursor = mydb.cursor()
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.get('/meetings/<id>')
|
|
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],
|
|
"start_time":result[2].strftime("%Y-%m-%d %H:%M:%S"),
|
|
"end_time":result[3] if result[3] == None else result[2].strftime("%Y-%m-%d %H:%M:%S")
|
|
}
|
|
|
|
@app.post('/meetings')
|
|
def create():
|
|
cursor.execute('INSERT INTO meetings (num_participants) VALUES (%s)', [request.json['num_participants']])
|
|
return request.json
|
|
|
|
@app.get('/<id>')
|
|
def home(id):
|
|
return render_template('home.html', id=id)
|