2017-09-30 09:34:17 +03:00
|
|
|
import requests
|
|
|
|
from flask import (
|
|
|
|
g, Blueprint, render_template, abort, current_app, redirect,
|
|
|
|
redirect, request, url_for, session, flash, jsonify
|
|
|
|
)
|
|
|
|
from jinja2 import TemplateNotFound
|
|
|
|
from wotstats.openid import oid
|
|
|
|
|
|
|
|
from wotstats.log import log
|
|
|
|
from wotstats.database import db
|
|
|
|
from wotstats.models import User
|
|
|
|
from wotstats.lib import parse_wargaming_openid_url
|
|
|
|
|
|
|
|
from .technic_list import t
|
|
|
|
|
|
|
|
pages_technic = Blueprint(
|
|
|
|
'technic', __name__, url_prefix='/technic', template_folder='templates')
|
|
|
|
|
|
|
|
def __get_technic():
|
|
|
|
log.debug(session)
|
|
|
|
user_id = parse_wargaming_openid_url(session['openid'])[0]
|
|
|
|
|
|
|
|
url = "https://api.worldoftanks.ru/wot/account/tanks/"
|
|
|
|
payload = {
|
|
|
|
"application_id": current_app.config['WG_APPLICATION_ID'],
|
|
|
|
"account_id": user_id
|
|
|
|
}
|
|
|
|
|
|
|
|
__ = requests.get(url, params=payload).json()
|
|
|
|
return __.get('data', {}).get(user_id)
|
|
|
|
|
|
|
|
|
|
|
|
@pages_technic.route('/')
|
|
|
|
def index():
|
|
|
|
"""Summary statistics"""
|
|
|
|
if not g.user:
|
|
|
|
return redirect(url_for('pages_home.index'))
|
|
|
|
|
|
|
|
# TODO: total accounts
|
|
|
|
#
|
|
|
|
account_technic = list()
|
|
|
|
for x in __get_technic():
|
|
|
|
x['details'] = t.get(str(x['tank_id']))
|
|
|
|
account_technic.append(x)
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
'pages/account/technic.html',
|
|
|
|
account_technic=account_technic
|
|
|
|
)
|
2017-10-29 17:31:48 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pages_technic.route('/list.json')
|
|
|
|
def list_json():
|
|
|
|
if not g.user:
|
|
|
|
return redirect(url_for('pages_home.index'))
|
|
|
|
|
|
|
|
list_levels = []
|
|
|
|
if len(request.args.getlist('level[]')) > 0:
|
|
|
|
list_levels = []
|
|
|
|
for i in request.args.getlist('level[]'):
|
|
|
|
list_levels.append(int(i))
|
|
|
|
|
|
|
|
# TODO: total accounts
|
|
|
|
#
|
|
|
|
account_technic = list()
|
|
|
|
|
|
|
|
for x in __get_technic():
|
|
|
|
if len(list_levels) == 0:
|
|
|
|
x['details'] = t.get(str(x['tank_id']))
|
|
|
|
account_technic.append(x)
|
|
|
|
else:
|
|
|
|
if t.get(str(x['tank_id'])).get('level') in list_levels:
|
|
|
|
x['details'] = t.get(str(x['tank_id']))
|
|
|
|
account_technic.append(x)
|
|
|
|
|
|
|
|
return jsonify(technic=account_technic)
|