1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-18 07:34:20 +00:00
royalnet/webserver.py

50 lines
1.9 KiB
Python
Raw Normal View History

2017-10-25 09:09:06 +00:00
from flask import Flask, render_template
2018-03-12 12:29:12 +00:00
from db import Session, Royal, Steam, RocketLeague, Dota, Osu, Overwatch, LeagueOfLegends, Diario, Telegram, PlayedMusic, Discord
2018-03-11 19:03:21 +00:00
from sqlalchemy import func
2017-10-25 09:09:06 +00:00
app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
2018-03-12 12:29:12 +00:00
2018-01-25 14:24:17 +00:00
@app.route("/")
def page_index():
return render_template("index.html")
2018-03-12 12:29:12 +00:00
2018-01-25 14:24:17 +00:00
@app.route("/diario")
def page_diario():
session = Session()
diario_data = session.query(Diario).outerjoin((Telegram, Diario.author), aliased=True).outerjoin(Royal, aliased=True).outerjoin((Telegram, Diario.saver), aliased=True).outerjoin(Royal, aliased=True).all()
session.close()
return render_template("diario.html", diario_data=diario_data)
2018-03-12 12:29:12 +00:00
2017-10-25 09:09:06 +00:00
@app.route("/leaderboards")
def page_leaderboards():
2017-10-30 09:46:37 +00:00
session = Session()
2018-01-25 14:24:17 +00:00
dota_data = session.query(Dota).join(Steam).join(Royal).order_by(Dota.rank_tier).all()
rl_data = session.query(RocketLeague).join(Steam).join(Royal).order_by(RocketLeague.doubles_mmr).all()
ow_data = session.query(Overwatch).join(Royal).order_by(Overwatch.rank).all()
osu_data = session.query(Osu).join(Royal).order_by(Osu.std_pp).all()
lol_data = session.query(LeagueOfLegends).join(Royal).order_by(LeagueOfLegends.summoner_name).all()
2017-10-30 09:46:37 +00:00
session.close()
2017-10-25 09:09:06 +00:00
return render_template("leaderboards.html", dota_data=dota_data, rl_data=rl_data, ow_data=ow_data, osu_data=osu_data, lol_data=lol_data)
2018-03-12 12:29:12 +00:00
2018-03-11 19:03:21 +00:00
@app.route("/music")
def page_music():
2018-02-02 10:46:27 +00:00
session = Session()
2018-03-12 12:29:12 +00:00
music_counts = session.query(PlayedMusic.filename, func.count(PlayedMusic.filename)).group_by(PlayedMusic.filename).all()
music_last = session.query(PlayedMusic).join(Discord).join(Royal).order_by(PlayedMusic.id.desc()).limit(50).all()
2018-02-02 10:46:27 +00:00
session.close()
2018-03-12 12:29:12 +00:00
return render_template("music.html", music_counts=music_counts, music_last=music_last)
2018-02-02 10:46:27 +00:00
2017-11-07 17:44:00 +00:00
2017-10-25 09:09:06 +00:00
if __name__ == "__main__":
2017-10-27 09:53:05 +00:00
try:
2018-01-25 14:29:38 +00:00
app.run(host="0.0.0.0", port=1234)
2017-10-27 09:53:05 +00:00
except KeyboardInterrupt:
2018-01-25 14:29:38 +00:00
pass