From 237a6711711cbc84c42b71da05ded4ffeed6dea5 Mon Sep 17 00:00:00 2001 From: binaryatrocity Date: Sun, 22 Jun 2014 23:20:59 -0500 Subject: [PATCH] Fix up A-Z stuff. --- .gitignore | 4 +- app.py | 4 +- app/models.py | 9 +++- app/templates/hero_random.html | 6 ++- migrations/versions/23bfef078b06_.py | 28 ----------- .../{47c81a0d0be7_.py => a6f7dd522b7_.py} | 49 ++++++++++--------- periodic.py | 4 +- 7 files changed, 43 insertions(+), 61 deletions(-) delete mode 100644 migrations/versions/23bfef078b06_.py rename migrations/versions/{47c81a0d0be7_.py => a6f7dd522b7_.py} (94%) diff --git a/.gitignore b/.gitignore index 23cb5c5..f0e1281 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,12 @@ __pycache__/ *.py[cod] *.so -static/img/hero-images/*.png +app/static/img/hero-images/ # DOTANOOBS config.py venv/ *.db +*.swp +clientlist.txt diff --git a/app.py b/app.py index e388569..ce0ab83 100755 --- a/app.py +++ b/app.py @@ -1,13 +1,11 @@ #!venv/bin/python -import os from flask import Flask from flask.ext.script import Manager, Server from flask.ext.migrate import Migrate, MigrateCommand from app import * -basedir = os.path.abspath(os.path.dirname(__file__)) -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'app.db') +SQLALCHEMY_DATABASE_URI = 'mysql://root:$perwePP@localhost/dotanoobs' migrate = Migrate(app, db) manager = Manager(app) diff --git a/app/models.py b/app/models.py index 3b214da..c3f5a18 100644 --- a/app/models.py +++ b/app/models.py @@ -6,7 +6,7 @@ from sqlalchemy.ext.mutable import Mutable import board from app import db, app -from utils import parse_valve_heropedia, complete_hero_data +from utils import parse_valve_heropedia, complete_hero_data, API_DATA # Model independant get_or_create def get_or_create_instance(session, model, **kwargs): @@ -73,6 +73,7 @@ class User(db.Model): last_seen = db.Column(db.DateTime) twitch = db.Column(db.String(60)) random_heroes = db.Column(MutableDict.as_mutable(Json)) + az_completions = db.Column(db.Integer) public = db.Column(db.Boolean) logo = db.Column(db.Boolean) @@ -94,6 +95,7 @@ class User(db.Model): def __init__(self, steam_id): self.steam_id = steam_id self.random_heroes = {'current':None, 'completed':[]} + self.az_completions = 0 self.created = datetime.utcnow() self.last_seen = datetime.utcnow() self.bio_text = None @@ -109,7 +111,7 @@ class User(db.Model): if not self.random_heroes['current']: heroes = [] for (tavern_name, tavern) in parse_valve_heropedia(): - heroes.extend([complete_hero_data('name', entry['name']) for entry in tavern]) + heroes.extend([complete_hero_data('name', entry['name']) for entry in tavern if entry['name'] not in self.random_heroes['completed']]) if heroes: self.random_heroes['current'] = choice(heroes) self.random_heroes = self.random_heroes @@ -128,6 +130,9 @@ class User(db.Model): def random_success(self): self.random_heroes['completed'].append(self.random_heroes['current']['name']) + if len(API_DATA['result']['heroes']) - len(self.random_heroes['completed']) <= 0: + self.az_completions = self.az_completions + 1 + del self.random_heroes['completed'][:] self.random_heroes['current'] = None self.random_heroes = self.random_heroes db.session.commit() diff --git a/app/templates/hero_random.html b/app/templates/hero_random.html index 6e8f754..7fe3af1 100644 --- a/app/templates/hero_random.html +++ b/app/templates/hero_random.html @@ -21,7 +21,7 @@

- {% if g.user and g.user.steamid == user.steamid %} + {% if g.user and g.user.steam_id == user.steam_id %}
@@ -31,7 +31,9 @@ {% endif %}
-
x1
+ {% if user.az_completions > 0 %} +
x{{ user.az_completions }}
+ {% endif %}

Completed

{% for hero in user.random_heroes.completed %} diff --git a/migrations/versions/23bfef078b06_.py b/migrations/versions/23bfef078b06_.py deleted file mode 100644 index dbee176..0000000 --- a/migrations/versions/23bfef078b06_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""empty message - -Revision ID: 23bfef078b06 -Revises: 47c81a0d0be7 -Create Date: 2014-06-22 18:04:41.935383 - -""" - -# revision identifiers, used by Alembic. -revision = '23bfef078b06' -down_revision = '47c81a0d0be7' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.add_column('user', sa.Column('winrate_interval', sa.Integer(), nullable=True)) - op.add_column('user', sa.Column('winrate_map', sa.Boolean(), nullable=True)) - ### end Alembic commands ### - - -def downgrade(): - ### commands auto generated by Alembic - please adjust! ### - op.drop_column('user', 'winrate_map') - op.drop_column('user', 'winrate_interval') - ### end Alembic commands ### diff --git a/migrations/versions/47c81a0d0be7_.py b/migrations/versions/a6f7dd522b7_.py similarity index 94% rename from migrations/versions/47c81a0d0be7_.py rename to migrations/versions/a6f7dd522b7_.py index 382d392..f22b83f 100644 --- a/migrations/versions/47c81a0d0be7_.py +++ b/migrations/versions/a6f7dd522b7_.py @@ -1,13 +1,13 @@ """empty message -Revision ID: 47c81a0d0be7 +Revision ID: a6f7dd522b7 Revises: None -Create Date: 2014-06-22 17:22:24.865474 +Create Date: 2014-06-22 22:35:25.691983 """ # revision identifiers, used by Alembic. -revision = '47c81a0d0be7' +revision = 'a6f7dd522b7' down_revision = None from alembic import op @@ -16,25 +16,6 @@ import sqlalchemy as sa def upgrade(): ### commands auto generated by Alembic - please adjust! ### - op.create_table('event', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('name', sa.String(length=200), nullable=True), - sa.Column('desc', sa.String(length=4096), nullable=True), - sa.Column('type', sa.String(length=20), nullable=True), - sa.Column('start_time', sa.DateTime(), nullable=True), - sa.Column('end_time', sa.DateTime(), nullable=True), - sa.Column('points', sa.Integer(), nullable=True), - sa.Column('reward_threshold', sa.Integer(), nullable=True), - sa.Column('total_subchans', sa.Integer(), nullable=True), - sa.Column('channels', sa.Json(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('teamspeak_data', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('time', sa.DateTime(), nullable=True), - sa.Column('clients', sa.Json(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) op.create_table('user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('steam_id', sa.String(length=40), nullable=True), @@ -48,6 +29,7 @@ def upgrade(): sa.Column('last_seen', sa.DateTime(), nullable=True), sa.Column('twitch', sa.String(length=60), nullable=True), sa.Column('random_heroes', sa.Json(), nullable=True), + sa.Column('az_completions', sa.Integer(), nullable=True), sa.Column('public', sa.Boolean(), nullable=True), sa.Column('logo', sa.Boolean(), nullable=True), sa.Column('points_from_events', sa.Integer(), nullable=True), @@ -62,12 +44,31 @@ def upgrade(): sa.UniqueConstraint('steam_id'), sa.UniqueConstraint('teamspeak_id') ) + op.create_table('teamspeak_data', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('time', sa.DateTime(), nullable=True), + sa.Column('clients', sa.Json(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('event', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=200), nullable=True), + sa.Column('desc', sa.String(length=4096), nullable=True), + sa.Column('type', sa.String(length=20), nullable=True), + sa.Column('start_time', sa.DateTime(), nullable=True), + sa.Column('end_time', sa.DateTime(), nullable=True), + sa.Column('points', sa.Integer(), nullable=True), + sa.Column('reward_threshold', sa.Integer(), nullable=True), + sa.Column('total_subchans', sa.Integer(), nullable=True), + sa.Column('channels', sa.Json(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) ### end Alembic commands ### def downgrade(): ### commands auto generated by Alembic - please adjust! ### - op.drop_table('user') - op.drop_table('teamspeak_data') op.drop_table('event') + op.drop_table('teamspeak_data') + op.drop_table('user') ### end Alembic commands ### diff --git a/periodic.py b/periodic.py index 97462d9..4395d64 100644 --- a/periodic.py +++ b/periodic.py @@ -181,10 +181,12 @@ def award_idle_ts3_points(server, cfg): doob.update_connection() active_users.add(doob) doobs = set(models.User.query.filter(models.User.ts3_starttime != None).all()) + ''' print doobs, active_users for doob in doobs.intersection(active_users): print(doob.nickname) - #doob.finalize_connection() + doob.finalize_connection() + ''' if __name__ == "__main__":