def handle_data(): Conn = Connection.getConnection() cursor = Conn.cursor() if request.form.get('type') == 'anon': comment = request.form.get('comment') author = "Anonymous" query = ( "INSERT INTO posts (author, comment, date, time) VALUES (%(author)s, %(comment)s, %(date)s, %(time)s)" ) today = datetime.now().date() if len(str(datetime.now().minute)) == 1: time = str(datetime.now().hour) + ":" + "0" + str( datetime.now().minute) + ":" + str(datetime.now().second) else: time = str(datetime.now().hour) + ":" + str( datetime.now().minute) + ":" + str(datetime.now().second) data = { 'author': author, 'comment': comment, 'date': today, 'time': time } cursor.execute(query, data) cursor.close() Conn.close() else: user = request.form.get('user') comment = request.form.get('comment') query = ( "INSERT INTO posts (author, comment, date, time) VALUES (%(author)s, %(comment)s, %(date)s, %(time)s)" ) today = datetime.now().date() if len(str(datetime.now().minute)) == 1: time = str(datetime.now().hour) + ":" + "0" + str( datetime.now().minute) + ":" + str(datetime.now().second) else: time = str(datetime.now().hour) + ":" + str( datetime.now().minute) + ":" + str(datetime.now().second) data = { 'author': user, 'comment': comment, 'date': today, 'time': time } cursor.execute(query, data) cursor.close() Conn.close() return redirect(url_for('share'))
def share(): Conn = Connection.getConnection() cursor = Conn.cursor() query = ("SELECT * FROM posts ORDER BY exact DESC") cursor.execute(query) return render_template('share.html', posts=cursor)