mirror of
https://github.com/RYGhub/song.git
synced 2024-11-23 05:24:20 +00:00
First and last commit
This commit is contained in:
commit
efcae33e62
3 changed files with 87 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.idea
|
||||
db.sqlite
|
||||
db.sqlite-journal
|
44
singasong.py
Normal file
44
singasong.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import datetime as dt
|
||||
from flask import Flask, session, request, render_template, abort, redirect, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
app.secret_key = "4pippo"
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
|
||||
|
||||
|
||||
class Song(db.Model):
|
||||
__tablename__ = "song"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
time = db.Column(db.DateTime, nullable=False)
|
||||
word = db.Column(db.String, nullable=False)
|
||||
|
||||
|
||||
@app.route('/', methods=["GET", "POST"])
|
||||
def page_main():
|
||||
if request.method == "GET":
|
||||
if session.get("last_entry") and session["last_entry"] < dt.datetime.now() + dt.timedelta(1):
|
||||
done = True
|
||||
else:
|
||||
done = False
|
||||
session["last_entry"] = None
|
||||
last_words = db.engine.execute("SELECT * FROM song ORDER BY time DESC LIMIT 3").fetchall()
|
||||
last_words.reverse()
|
||||
return render_template("song.html", last_words=last_words, done=done)
|
||||
elif request.method == "POST":
|
||||
if session.get("last_entry") and session["last_entry"] < dt.datetime.now() + dt.timedelta(1):
|
||||
abort(403)
|
||||
new_word = Song(time=dt.datetime.now(), word=request.form["word"].split(" ")[0])
|
||||
db.session.add(new_word)
|
||||
db.session.commit()
|
||||
session["last_entry"] = dt.datetime.now()
|
||||
return redirect(url_for("page_main"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
db.create_all()
|
||||
app.run()
|
40
templates/song.html
Normal file
40
templates/song.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>La Canzone Royal Games</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #190c00;
|
||||
color: #ff7f00;
|
||||
}
|
||||
|
||||
.word {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
form, form.inline input {
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Continua la canzone Royal Games con una parola!
|
||||
</h1>
|
||||
<h3>
|
||||
Puoi aggiungere una parola una volta al giorno.g
|
||||
</h3>
|
||||
<div>
|
||||
...
|
||||
{% for word in last_words %}
|
||||
<span class="word" id="last-word-{{ loop.index }}">{{ word[2] }}</span>
|
||||
{% endfor %}
|
||||
<form class="inline" method="POST">
|
||||
<input name="word" {% if done %}disabled placeholder="Torna domani!"{% else %}placeholder="Continua tu!"{% endif %}>
|
||||
<input type="submit" value="Aggiungi" {% if done %}disabled{% endif %}>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue