diff options
-rw-r--r-- | f1elo/db.py | 13 | ||||
-rw-r--r-- | f1elo/model.py | 11 | ||||
-rw-r--r-- | import-csv.py | 2 |
3 files changed, 13 insertions, 13 deletions
diff --git a/f1elo/db.py b/f1elo/db.py index 8ecb0ac..f4ed307 100644 --- a/f1elo/db.py +++ b/f1elo/db.py @@ -2,7 +2,6 @@ import json from os import path import __main__ -from f1elo.model import Driver from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker @@ -11,15 +10,5 @@ if config['engine'] == 'mysql': engine = create_engine("mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}?charset=utf8".format(config)) else: engine = create_engine("sqlite:///{0[file]}".format(config)) -Session = sessionmaker(bind=engine) -def find_driver(name, country, session): - driver = session.query(Driver).filter(Driver.driver==name).first() - if driver: - return driver - else: - driver = Driver() - driver.driver = name - driver.country = country - session.add(driver) - return driver +Session = sessionmaker(bind=engine) diff --git a/f1elo/model.py b/f1elo/model.py index 4b893dc..7865198 100644 --- a/f1elo/model.py +++ b/f1elo/model.py @@ -85,5 +85,16 @@ class Ranking(Base): def __repr__(self): return ("%s: %0.2f (%s)" % (self.driver.__repr__().decode('utf8'), self.ranking, self. rank_date)).encode('utf8') +def find_driver(name, country, session): + driver = session.query(Driver).filter(Driver.driver==name).first() + if driver: + return driver + else: + driver = Driver() + driver.driver = name + driver.country = country + session.add(driver) + return driver + __all__ = ['Driver', 'Entry', 'Ranking', 'Race', 'RaceType'] diff --git a/import-csv.py b/import-csv.py index ae4b9e6..ff65425 100644 --- a/import-csv.py +++ b/import-csv.py @@ -1,7 +1,7 @@ import csv import sys -from f1elo.db import find_driver, Session +from f1elo.model import find_driver, Session from f1elo.model import * session = Session() |