Skip to content

Commit 8a26646

Browse files
committed
wip
1 parent 33ce3c5 commit 8a26646

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

orga2Utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
from sqlalchemy.orm import sessionmaker
66
from sqlalchemy import func
77
# Local imports
8-
from models import AsmInstruction, Noitip, Session, init_db
8+
import models
99

1010
@contextmanager
1111
def get_session():
1212
"""Provide a transactional scope around a series of operations."""
13-
global Session
14-
if Session is None:
15-
init_db()
16-
session = Session()
13+
if models.Session is None:
14+
models.init_db()
15+
session = models.Session()
1716
try:
1817
yield session
1918
session.commit()
@@ -26,7 +25,7 @@ def get_session():
2625

2726
def noitip(update, context):
2827
with get_session() as session:
29-
random_noitip = session.query(Noitip).order_by(func.random()).first().text
28+
random_noitip = session.query(models.Noitip).order_by(func.random()).first().text
3029
msg = update.message.reply_text(random_noitip, quote=False)
3130
context.sent_messages.append(msg)
3231

@@ -40,7 +39,7 @@ def asm(update, context):
4039

4140
mnemonic = " ".join(context.args).upper()
4241
with get_session() as session:
43-
all_instructions = session.query(AsmInstruction).all()
42+
all_instructions = session.query(models.AsmInstruction).all()
4443
possibles = [i for i in all_instructions
4544
if levenshtein(mnemonic, i.mnemonic.upper()) < 2]
4645
if not possibles:

0 commit comments

Comments
 (0)