ventilaar
/
twitter_zuil
Archived
1
Fork 0

autoqueue werkt???, nog verder testen. maar het lijkt te werken

This commit is contained in:
ventilaar 2020-11-02 11:50:02 +01:00
parent 93a1aac507
commit ec926e1108
6 changed files with 148 additions and 14 deletions

View File

@ -3,12 +3,25 @@ from TwitterAPI import TwitterAPI
from api_keys import *
import database_connector
import hashlib
import secrets
import datetime
# TESTING
debug = True
# langere commands korter maken
conn = database_connector.conn
cur = database_connector.cur
# flask startup
app = Flask(__name__)
app.secret_key = b'890hj3h5gh0i8n5h0g8ni3hg50n8i'
# genereert na elke opstart een andere secret key zodat usersessies ook invalidated worden
if debug == True:
app.secret_key = 'jdndhsyh83r90hfeqwf' # dit is om live te testen
else:
app.secret_key = secrets.token_hex(32)
def func_check_login(uname, pword):
hashedpass = hashlib.sha256(pword.encode('UTF-8') + 'saltandpepper'.encode('UTF-8')).hexdigest()
@ -76,7 +89,7 @@ def func_removemoderator(moderatorid):
try:
cur.execute('UPDATE moderators SET maylogin = false WHERE moderatorid = (%s)', [moderatorid])
conn.commit()
flash('Account kan niet verwijdert worden, account mag niet meer inloggen')
flash('Account kan niet verwijdert worden, account nu mag niet meer inloggen')
return True
except:
conn.rollback()
@ -107,9 +120,50 @@ def func_querybericht(berichtid):
'WHERE berichtid = (%s)', [berichtid])
return cur.fetchone()
def func_lockbericht(berichtid, moderatorid):
cur.execute('UPDATE berichten SET statusid = 2, moderatorid = (%s) WHERE berichtid = (%s)', (moderatorid, berichtid))
def func_autoqueuebericht(moderatornaam):
cur.execute('SELECT berichten.berichtid, berichten.bericht, berichten.datumontvangen, berichten.naamposter, '
'locaties.naam, statuses.status '
'FROM berichten '
'LEFT OUTER JOIN statuses ON berichten.statusid = statuses.statusid '
'LEFT OUTER JOIN locaties ON berichten.locatieid = locaties.locatieid '
'LEFT OUTER JOIN moderators ON berichten.moderatorid = moderators.moderatorid '
'WHERE berichten.statusid = 1 ORDER BY datumontvangen LIMIT 1')
bericht = cur.fetchone()
if bericht == None:
flash('Er zijn geen berichten meer om te keuren, probeer het later opnieuw')
return False
cur.execute('SELECT moderatorid FROM moderators WHERE naam = (%s)', [moderatornaam])
moderatorid = cur.fetchone()[0]
cur.execute('UPDATE berichten SET statusid = 2, moderatorid = (%s) WHERE berichtid = (%s)', (moderatorid, bericht[0]))
conn.commit()
return bericht
def func_unlockbericht(berichtid):
cur.execute("UPDATE berichten SET statusid = 1, moderatorid = NULL WHERE berichtid = (%s)", [berichtid])
conn.commit()
return True
def func_messageaccept(berichtid):
date = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
QUERY = "UPDATE berichten SET statusid = 4, datumgekeurd = (%s) WHERE berichtid = (%s)"
DATA = (date, berichtid)
cur.execute(QUERY, DATA)
conn.commit()
return True
def func_messagereject(berichtid):
date = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
QUERY = "UPDATE berichten SET statusid = 3, datumgekeurd = (%s) WHERE berichtid = (%s)"
DATA = (date, berichtid)
cur.execute(QUERY, DATA)
conn.commit()
return True
def func_publish_twitter(berichtid):
return True
@ -135,7 +189,7 @@ def login():
@app.route('/home')
def home():
if 'username' in session:
return render_template('home.html', username = session['username'])
return render_template('home.html', username=session['username'])
else:
flash('You are not logged in!')
return redirect(url_for('login'))
@ -217,7 +271,47 @@ def bericht(berichtid):
flash('You are not logged in!')
return redirect(url_for('login'))
@app.route('/autoqueue', methods=['GET', 'POST'])
def autoqueue():
if 'username' in session:
if request.method == 'POST':
if func_unlockbericht(request.form['stop']):
return redirect(url_for('home'))
else:
flash('probleem met het unlocken van het bericht')
return redirect(url_for('home'))
else:
bericht = func_autoqueuebericht(session['username'])
if bericht == False:
return redirect(url_for('home'))
return render_template('autoqueue.html', bericht=bericht)
else:
flash('You are not logged in!')
return redirect(url_for('login'))
@app.route('/autoqueue/accept', methods=['POST'])
def autoqueue_accept():
if 'username' in session:
if func_messageaccept(request.form['good']):
return redirect(url_for('autoqueue'))
else:
return redirect(url_for('autoqueue'))
else:
flash('You are not logged in!')
return redirect(url_for('login'))
@app.route('/autoqueue/reject', methods=['POST'])
def autoqueue_reject():
if 'username' in session:
if func_messagereject(request.form['bad']):
return redirect(url_for('autoqueue'))
else:
return redirect(url_for('autoqueue'))
else:
flash('You are not logged in!')
return redirect(url_for('login'))
if __name__ == "__main__":
app.run('0.0.0.0', debug=True)
app.run('0.0.0.0', debug=debug)

View File

@ -1,10 +1,7 @@
.flashes {
color: green;
}
ul {
list-style-type: none;
margin: 0;

40
templates/autoqueue.html Normal file
View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"/>
</head>
<body>
{% include 'flash_template.html' %}
<h1>Bericht autoqueue</h1>
<p>Berichten in de wachtrij goedkeuren</p>
<form method="POST">
<button type="submit" name="stop" value="{{ bericht[0] }}" class="stopknop">Klik hier om te stoppen</button>
</form>
<table style="width:100%">
<tr>
<th>Bericht ID</th>
<th>Naam</th>
<th>Bericht inhoud</th>
<th>Geplaatst in</th>
<th>Ontvangen op</th>
<th>Status bericht</th>
</tr>
<tr>
<th>{{ bericht[0] }}</th>
<th>{{ bericht[3] }}</th>
<th>{{ bericht[1] }}</th>
<th>{{ bericht[4] }}</th>
<th>{{ bericht[2] }}</th>
<th>{{ bericht[5] }}</th>
</tr>
</table>
<form method="POST" action="/autoqueue/accept">
<button type="submit" name="good" value="{{ bericht[0] }}" class="keurknoppen">Goedkeuren en publiceren</button>
</form>
<form method="POST" action="/autoqueue/reject">
<button type="submit" name="bad" value="{{ bericht[0] }}" class="keurknoppen">Afkeuren</button>
</form>
</body>
</html>

View File

@ -8,7 +8,7 @@
<body>
{% include 'navbar_template.html' %}
{% include 'flash_template.html' %}
<h1>Bericht ID {{ berichtid }}</h1>
<h1>Bericht bekijken</h1>
<table style="width:100%">
<tr>
<th>Bericht ID</th>
@ -17,8 +17,9 @@
<th>Geplaatst in</th>
<th>Ontvangen op</th>
<th>Status bericht</th>
<th>Gekeurd op</th>
<th>Moderator</th>
<th>Gekeurd op</th>
<th>Twitter ID</th>
</tr>
<tr>
@ -28,9 +29,10 @@
<th>{{ bericht[5] }}</th>
<th>{{ bericht[2] }}</th>
<th>{{ bericht[7] }}</th>
<th>{{ bericht[4] }}</th>
<th>{{ bericht[6] }}</th>
<th>{{ bericht[4] }}</th>
<th>{{ bericht[8] }}</th>
</tr>
</table>
</body>
</html>

View File

@ -18,8 +18,8 @@
<th>Geplaatst in</th>
<th>Ontvangen op</th>
<th>Status bericht</th>
<th>Gekeurd op</th>
<th>Moderator</th>
<th>Gekeurd op</th>
<th>Twitter ID</th>
</tr>
{% for row in berichten %}
@ -30,8 +30,8 @@
<th>{{ row[5] }}</th>
<th>{{ row[2] }}</th>
<th>{{ row[7] }}</th>
<th>{{ row[4] }}</th>
<th>{{ row[6] }}</th>
<th>{{ row[4] }}</th>
<th>{{ row[8] }}</th>
</tr>
{% endfor %}

View File

@ -3,5 +3,6 @@
<li><a href="/home">Home</a></li>
<li><a href="/moderators">Moderators</a></li>
<li><a href="/berichten">Berichten</a></li>
<li><a href="/autoqueue" style="float:right;">Berichten Autoqueue</a></li>
<li><a href="/login" style="float:right;">Login/Logout</a></li>
</ul>