blob: 49ccc3dd6d8da61a093fdf4dce32d7833cdbae1c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import __main__
from os import path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import json
config = json.load(open(path.dirname(__main__.__file__) + '/config/db.json'))
engine = create_engine("mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}?charset=utf8".format(config))
Session = sessionmaker(bind=engine)
from f1elo.model import Driver
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
|