105 lines
3.2 KiB
Python
105 lines
3.2 KiB
Python
import requests
|
|
from flask import (
|
|
g, Blueprint, render_template, abort, current_app, redirect,
|
|
redirect, request, url_for, session, flash
|
|
)
|
|
from jinja2 import TemplateNotFound
|
|
from wotstats.openid import oid
|
|
|
|
from wotstats.database import db
|
|
from wotstats.models import Rush, RushAccounts, WotAccounts
|
|
from wotstats.lib import parse_wargaming_openid_url
|
|
|
|
pages_rush = Blueprint(
|
|
'pages_rush', __name__,
|
|
url_prefix='/rush',
|
|
template_folder='templates')
|
|
|
|
|
|
@pages_rush.route('/')
|
|
def index():
|
|
if not g.user:
|
|
return redirect(url_for('pages_home.index'))
|
|
|
|
rush_list = Rush.query.all()
|
|
|
|
rush_preparation = Rush.query.filter(Rush.status == 'preparation').first()
|
|
|
|
rush_list_accounts = RushAccounts.query.filter(RushAccounts.rush_id == rush_preparation.id).all()
|
|
|
|
account_id, account_nickname = parse_wargaming_openid_url(session['openid'])
|
|
|
|
# #
|
|
# app_id = current_app.config['WG_APPLICATION_ID']
|
|
# url = 'https://api.worldoftanks.ru/wot/account/info/'
|
|
# __ = requests.get('{}?application_id={}&account_id={}'.format(url, app_id, account_id)).json()
|
|
# # if not __.get('data', {}).get("{}".format(account_id)):
|
|
# # print('account_id: {} SKIPPED'.format(account_id))
|
|
# # continue
|
|
# # copy results
|
|
# account_statistics = __.get('data', {}).get("{}".format(account_id)).get('statistics', {})
|
|
# account_data = __['data']["{}".format(account_id)]['statistics']['all']
|
|
#
|
|
# data = {
|
|
# 'battles': account_data['battles'],
|
|
# 'wins': account_data['wins'],
|
|
# 'losses': account_data['losses'],
|
|
# 'draws': account_data['draws'],
|
|
# }
|
|
|
|
# account_data.pop('statistics', None)
|
|
|
|
# db.session.add(WotAccounts(account_id=account_id, nickname=account_data.get('nickname')))
|
|
# db.session.commit()
|
|
# db.session.flush()
|
|
|
|
# ws = WotAccountsStats()
|
|
# ws.account_id = account_id
|
|
# ws.created_at = datetime.now()
|
|
# try:
|
|
# ws.last_battle_time = datetime.fromtimestamp(int(account_data.get('last_battle_time'))).strftime('%Y-%m-%d %H:%M:%S')
|
|
# except Exception as e:
|
|
# print('>> Error: {}'.format(e))
|
|
# ws.data = account_data
|
|
# ws.statistics = account_statistics
|
|
# db.session.add(ws)
|
|
# db.session.commit()
|
|
# db.session.flush()
|
|
|
|
|
|
|
|
return render_template(
|
|
'pages/rush/index.html',
|
|
rush_list=rush_list,
|
|
rush_list_accounts=rush_list_accounts,
|
|
account_id=account_id, account_nickname=account_nickname
|
|
)
|
|
|
|
@pages_rush.route('/apply.html')
|
|
def apply():
|
|
if not g.user:
|
|
return redirect(url_for('pages_home.index'))
|
|
|
|
rush_prep = Rush.query.filter(Rush.status == 'preparation').first()
|
|
|
|
return render_template(
|
|
'pages/rush/apply.html',
|
|
rush=rush_prep
|
|
)
|
|
|
|
@pages_rush.route('/apply.html', methods=['POST'])
|
|
def apply_post():
|
|
if not g.user:
|
|
return redirect(url_for('pages_home.index'))
|
|
|
|
r = Rush.query.filter(Rush.status == 'preparation').first()
|
|
wa = WotAccounts.query.filter(WotAccounts.user == session['user']).first()
|
|
|
|
ra = RushAccounts(rush_id=r.id, account_id=wa.account_id)
|
|
ra.start_data = {}
|
|
ra.finish_data = {}
|
|
|
|
db.session.add(ra)
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('pages_rush.apply'))
|