update indexer
This commit is contained in:
parent
5694fe1676
commit
5f338d30e9
4 changed files with 46 additions and 4 deletions
Binary file not shown.
19
manage.py
19
manage.py
|
@ -32,6 +32,19 @@ def wot_harvest_accounts():
|
|||
if _account_id:
|
||||
account_id = _account_id
|
||||
|
||||
for i in db.session.query(WotAccountsStats.id, WotAccountsStats.last_battle_time, WotAccountsStats.data).filter(WotAccountsStats.last_battle_time == None):
|
||||
print i.id
|
||||
x = db.session.query(WotAccountsStats).filter_by(id=i.id).first()
|
||||
|
||||
# x = WotAccountsStats.query.filter_by(id=i.id)
|
||||
# print x.account_id
|
||||
x.last_battle_time = datetime.fromtimestamp(int(i.data.get('last_battle_time'))).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# i.last_battle_time = datetime.fromtimestamp(int(i.data.get('last_battle_time'))).strftime('%Y-%m-%d %H:%M:%S')
|
||||
db.session.commit()
|
||||
# db.session.flush()
|
||||
# return
|
||||
|
||||
while True:
|
||||
account_id += 1
|
||||
__ = requests.get('{}?application_id={}&account_id={}'.format(url, app_id, account_id)).json()
|
||||
|
@ -50,14 +63,16 @@ def wot_harvest_accounts():
|
|||
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()
|
||||
|
||||
|
||||
|
||||
print('account_id: {} nickname: {} OK'.format(account_id, account_data.get('nickname')))
|
||||
|
||||
# break
|
||||
|
|
26
migrations/versions/e75eb58a894e_.py
Normal file
26
migrations/versions/e75eb58a894e_.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: e75eb58a894e
|
||||
Revises: 49d6ea45c818
|
||||
Create Date: 2017-09-19 01:51:33.902548
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'e75eb58a894e'
|
||||
down_revision = '49d6ea45c818'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column(
|
||||
'wot_accounts_stats',
|
||||
sa.Column('last_battle_time', sa.DateTime(), nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('wot_accounts_stats', 'last_battle_time')
|
|
@ -7,6 +7,7 @@ class WotAccountsStats(db.Model):
|
|||
id = db.Column(db.Integer, primary_key=True)
|
||||
account_id = db.Column(db.Integer, db.ForeignKey('wot_accounts.id'), nullable=False)
|
||||
created_at = db.Column(db.DateTime, nullable=False)
|
||||
last_battle_time = db.Column(db.DateTime, nullable=True)
|
||||
# WG
|
||||
data = db.Column(JSONB, nullable=False, default={})
|
||||
statistics = db.Column(JSONB, nullable=False, default={})
|
||||
|
@ -15,5 +16,5 @@ class WotAccountsStats(db.Model):
|
|||
# pass
|
||||
|
||||
def __repr__(self):
|
||||
return '<WotAccountsStats id={} account_id={} created_at={}>'.format(
|
||||
self.id, self.user, self.created_at)
|
||||
return '<WotAccountsStats id={} account_id={} created_at={} last_battle_time={}>'.format(
|
||||
self.id, self.account_id, self.created_at, self.last_battle_time)
|
||||
|
|
Reference in a new issue