syntax/linting fixes

This commit is contained in:
Aaron Kimbre
2022-03-12 20:09:35 -06:00
parent 70742549b9
commit 5ce9ac85bc
18 changed files with 504 additions and 375 deletions

View File

@@ -1,11 +1,13 @@
from flask import render_template, Blueprint, redirect, url_for, request, abort, flash, request, current_app
from flask_user import login_required, current_user
from app.models import db, CharacterInfo, Account, CharacterXML, Reports
from flask import render_template, Blueprint, current_app
from flask_user import login_required
from app.models import CharacterInfo, Account, CharacterXML, Reports
from app import gm_level, scheduler
import datetime, xmltodict, json
import datetime
import xmltodict
reports_blueprint = Blueprint('reports', __name__)
@reports_blueprint.route('/', methods=['GET', 'POST'])
@login_required
@gm_level(3)
@@ -13,25 +15,28 @@ def index():
reports = Reports.query.distinct(Reports.date).group_by(Reports.date).all()
return render_template('reports/index.html.j2', reports=reports)
@reports_blueprint.route('/items/by_date/<date>', methods=['GET', 'POST'])
@login_required
@gm_level(3)
def items_by_date(date):
data = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="items").first().data
data = Reports.query.filter(Reports.date == date).filter(Reports.report_type == "items").first().data
return render_template('reports/items/by_date.html.j2', data=data, date=date)
@reports_blueprint.route('/currency/by_date/<date>', methods=['GET', 'POST'])
@login_required
@gm_level(3)
def currency_by_date(date):
data = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="currency").first().data
data = Reports.query.filter(Reports.date == date).filter(Reports.report_type == "currency").first().data
return render_template('reports/currency/by_date.html.j2', data=data, date=date)
@reports_blueprint.route('/uscore/by_date/<date>', methods=['GET', 'POST'])
@login_required
@gm_level(3)
def uscore_by_date(date):
data = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="uscore").first().data
data = Reports.query.filter(Reports.date == date).filter(Reports.report_type == "uscore").first().data
return render_template('reports/uscore/by_date.html.j2', data=data, date=date)
@@ -42,22 +47,22 @@ def gen_item_report():
current_app.logger.info("Start Item Report Generation")
date = datetime.date.today().strftime('%Y-%m-%d')
report = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="items").first()
report = Reports.query.filter(Reports.date == date).filter(Reports.report_type == "items").first()
# Only one report per day
if report != None:
if report not None:
current_app.logger.info(f"Item Report Already Generated for {date}")
return
char_xmls = CharacterXML.query.join(
CharacterInfo,
CharacterInfo.id==CharacterXML.id
).join(
Account,
CharacterInfo.account_id==Account.id
).filter(Account.gm_level < 3).all()
CharacterInfo,
CharacterInfo.id == CharacterXML.id
).join(
Account,
CharacterInfo.account_id == Account.id
).filter(Account.gm_level < 3).all()
report_data={}
report_data = {}
for char_xml in char_xmls:
try:
@@ -66,7 +71,7 @@ def gen_item_report():
attr_prefix="attr_"
)
for inv in character_json["obj"]["inv"]["items"]["in"]:
if "i" in inv.keys() and type(inv["i"]) == list and (int(inv["attr_t"])==0 or int(inv["attr_t"])==1):
if "i" in inv.keys() and type(inv["i"]) == list and (int(inv["attr_t"]) == 0 or int(inv["attr_t"]) == 1):
for item in inv["i"]:
if item["attr_l"] in report_data:
report_data[item["attr_l"]] = report_data[item["attr_l"]] + int(item["attr_c"])
@@ -96,22 +101,22 @@ def gen_currency_report():
current_app.logger.info("Start Currency Report Generation")
date = datetime.date.today().strftime('%Y-%m-%d')
report = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="currency").first()
report = Reports.query.filter(Reports.date == date).filter(Reports.report_type == "currency").first()
# Only one report per day
if report != None:
if report not None:
current_app.logger.info(f"Currency Report Already Generated for {date}")
return
characters = CharacterXML.query.join(
CharacterInfo,
CharacterInfo.id==CharacterXML.id
).join(
Account,
CharacterInfo.account_id==Account.id
).filter(Account.gm_level < 3).all()
CharacterInfo,
CharacterInfo.id == CharacterXML.id
).join(
Account,
CharacterInfo.account_id == Account.id
).filter(Account.gm_level < 3).all()
report_data={}
report_data = {}
for character in characters:
try:
@@ -119,7 +124,7 @@ def gen_currency_report():
character.xml_data,
attr_prefix="attr_"
)
report_data[CharacterInfo.query.filter(CharacterInfo.id==character.id).first().name] = int(character_json["obj"]["char"]["attr_cc"])
report_data[CharacterInfo.query.filter(CharacterInfo.id == character.id).first().name] = int(character_json["obj"]["char"]["attr_cc"])
except Exception as e:
current_app.logger.error(f"REPORT::CURRENCY - ERROR PARSING CHARACTER {char_xml.id}")
current_app.logger.error(f"REPORT::CURRENCY - {e}")
@@ -144,22 +149,22 @@ def gen_uscore_report():
current_app.logger.info("Start U-Score Report Generation")
date = datetime.date.today().strftime('%Y-%m-%d')
report = Reports.query.filter(Reports.date==date).filter(Reports.report_type=="uscore").first()
report = Reports.query.filter(Reports.date == date).filter(Reports.report_type == "uscore").first()
# Only one report per day
if report != None:
if report not None:
current_app.logger.info(f"U-Score Report Already Generated for {date}")
return
characters = CharacterXML.query.join(
CharacterInfo,
CharacterInfo.id==CharacterXML.id
).join(
Account,
CharacterInfo.account_id==Account.id
).filter(Account.gm_level < 3).all()
CharacterInfo,
CharacterInfo.id == CharacterXML.id
).join(
Account,
CharacterInfo.account_id == Account.id
).filter(Account.gm_level < 3).all()
report_data={}
report_data = {}
for character in characters:
try:
@@ -167,7 +172,7 @@ def gen_uscore_report():
character.xml_data,
attr_prefix="attr_"
)
report_data[CharacterInfo.query.filter(CharacterInfo.id==character.id).first().name] = int(character_json["obj"]["char"]["attr_ls"])
report_data[CharacterInfo.query.filter(CharacterInfo.id == character.id).first().name] = int(character_json["obj"]["char"]["attr_ls"])
except Exception as e:
current_app.logger.error(f"REPORT::U-SCORE - ERROR PARSING CHARACTER {char_xml.id}")
current_app.logger.error(f"REPORT::U-SCORE - {e}")