-
Notifications
You must be signed in to change notification settings - Fork 0
/
webui.py
73 lines (61 loc) · 2.23 KB
/
webui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from clashapp import flaskapp, db
from clashapp.models import clan_model, player_model
from flask import render_template, request, redirect
from clashapp.collector import ClanData
@flaskapp.route('/', methods=["GET", "POST"])
def home(**kwargs):
clan = None
clanInst = {}
if request.form:
try:
clan = clan_model.ClansStatsRecent(clanTag=request.form.get("title"))
clanInst = ClanData(clan.clan_tag)
clanInst.populate_clan_info()
clan.clanLevel = clanInst.clan_level
clan.clanName = clanInst.clan_name
clan.avgQueenLevel = str(clanInst.get_avg_hero_level_by_th('queen'))
clan.clanPoints = clanInst.clan_points
clan.memberCount = clanInst.member_count
clan.warWins = clanInst.war_wins
clan.warLosses = clanInst.war_losses
# clan.members = list(clanInst.memberDict.values())
#
# print([i.kingLevel for i in clan.members])
#
# print(clanInst.memberDict)
#
# c = ClanData(clan.clanTag)
# c.get_all_clan_info()
# print(c.clanLevel)
#
# a = c.get_avg_hero_level_by_th('queen')
#
# print(a)
db.session.add(clan)
db.session.commit()
except Exception as e:
print("Failed to add clan tag")
print(e)
clan = clan_model.ClansStatsRecent.query.all()
return render_template("home.html", clans=clan)
@flaskapp.route("/update", methods=["POST"])
def update():
try:
newtitle = request.form.get("newtitle")
oldtitle = request.form.get("oldtitle")
clan = clan_model.ClansStatsRecent.query.filter_by(clanTag=oldtitle).first()
clan.clanTag = newtitle
db.session.commit()
except Exception as e:
print("Couldn't update clan tag")
print(e)
return redirect("/")
@flaskapp.route("/delete", methods=["POST"])
def delete():
clanTag = request.form.get("title")
clan = clan_model.ClansStatsRecent.query.filter_by(clanTag=clanTag).first()
db.session.delete(clan)
db.session.commit()
return redirect("/")
if __name__ == "__main__":
flaskapp.run(debug=True)