import flask import datetime import random import string import os app = flask.Flask(__name__) code = "" history = [] @app.route('/musicstatus.html', methods=['GET', 'POST']) def musicstatus(): global code, history if flask.request.method == 'POST': data = flask.request.get_json() if code == "": return "Verification code not generated" if data['verificationcode'] != code: return "Verification failed" else: musicname = data['music'] time = data['time'] resetstatus = data['resetstatus'] history.append((musicname, time, resetstatus)) return f"{musicname} added to history" elif flask.request.method == 'GET': html = '\n\n' html += '\n\n\n\n' html += '\n\n' html += 'Halhadus\' Music Status\n\n' html += '\n\n' html += '\n\n' html += '\n' html += '

Halhadus\' Music Status

\n' html += 'Source Code\n' html += '

Hi guys. I am too lazy to add links to song names. To find which song is it, check this link.

\n' html += '
\n\n
\n' if len(history) > 0: if history[-1][2] == "true": currentbeforereset = history[-1] history = [] history.append(currentbeforereset) html += f'

Currently Playing: {history[-1][0]}

\n' html += f'

Last Update Time: {datetime.datetime.fromtimestamp(int(history[-1][1]), datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")} (UTC +0)

\n' if os.path.exists("lyrics/" + history[-1][0] + ".txt"): with open("lyrics/" + history[-1][0] + ".txt", "r") as f: html += f'

Lyrics:

\n

{f.read()}

\n' html += '\n\n\n\n\n' for music in history[::-1]: html += '\n\n\n\n' html += '
Music NameTime
' + music[0] + '' + datetime.datetime.fromtimestamp(int(music[1]), datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S") + '
\n\n' return html @app.route('/verifykey', methods=['GET', 'POST']) def verifycert(): global code if flask.request.method == 'POST': data = flask.request.get_json() key = data['key'] with open("key.txt", "r") as f: if key == f.read(): code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=64)) return code else: return "0" elif flask.request.method == 'GET': return "GET method not allowed" @app.route('/') def catch_all(path): if path == None: return flask.redirect('https://halhadus.rocks') if not path == 'musicstatus.html' or not path == 'verifykey': return flask.redirect(f'https://halhadus.rocks/{path}') if __name__ == '__main__': app.run(host='0.0.0.0', port=int(os.environ.get('PORT')))