summaryrefslogtreecommitdiff
path: root/ausbutler
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-01-04 00:45:26 +0100
committeremkael <emkael@tlen.pl>2017-01-04 20:56:23 +0100
commit63ab18bb8903ddd8d88516fda450b815329ab357 (patch)
tree997a152c68106d0dc085517b066bb2c06fed671e /ausbutler
parentb231002cd6bd5df74867627576a75c510b41e1f1 (diff)
Code reformatting
Diffstat (limited to 'ausbutler')
-rw-r--r--ausbutler/db.py15
-rw-r--r--ausbutler/interface.py10
-rw-r--r--ausbutler/model.py6
3 files changed, 17 insertions, 14 deletions
diff --git a/ausbutler/db.py b/ausbutler/db.py
index a53a273..940c69d 100644
--- a/ausbutler/db.py
+++ b/ausbutler/db.py
@@ -1,14 +1,15 @@
import json
from os import path
-from sqlalchemy import create_engine, event
+from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import __main__
-config = json.load(
- open(path.join(path.dirname(__main__.__file__), 'config', 'db.json')))
-engine = create_engine(
- "mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}".format(config))
-
-Session = sessionmaker(bind=engine)
+def get_session():
+ session = sessionmaker(bind=create_engine(
+ "mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}".format(
+ json.load(open(
+ path.join(path.dirname(__main__.__file__), 'config', 'db.json')
+ )))))
+ return session()
diff --git a/ausbutler/interface.py b/ausbutler/interface.py
index 94b61e4..dd58b76 100644
--- a/ausbutler/interface.py
+++ b/ausbutler/interface.py
@@ -1,14 +1,14 @@
import re
from .butler import cutoff, get_opponents, get_room, normalize
-from .db import Session
+from .db import get_session
from .model import AusButler, Butler
-class Interface:
+class Interface(object):
def __init__(self, config):
- self.session = Session()
+ self.session = get_session()
self.config = config
def init_db(self, force=False):
@@ -46,7 +46,9 @@ class Interface:
averages = {opps[0]: {'sum': 0.0, 'count': 0},
opps[1]: {'sum': 0.0, 'count': 0}}
for opp_butler in butlers:
- if opp_butler.id in opps and (opp_butler.match < butler.match or (opp_butler.match == butler.match and opp_butler.segment < butler.segment)):
+ if opp_butler.id in opps \
+ and (opp_butler.match < butler.match or \
+ (opp_butler.match == butler.match and opp_butler.segment < butler.segment)):
averages[opp_butler.id]['sum'] += opp_butler.score
averages[opp_butler.id]['count'] += opp_butler.board_count
butler.opp_score = sum(
diff --git a/ausbutler/model.py b/ausbutler/model.py
index cb17ce9..6536b6a 100644
--- a/ausbutler/model.py
+++ b/ausbutler/model.py
@@ -1,12 +1,12 @@
from cached_property import cached_property
-from sqlalchemy import Column, ForeignKey, MetaData, Table, func
+from sqlalchemy import Column, MetaData, Table, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.types import Float, Integer
-from .db import Session
+from .db import get_session
Base = declarative_base()
-session = Session()
+session = get_session()
class AusButler(Base):
__tablename__ = 'aus_butler'