File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55from sqlalchemy .orm import sessionmaker
66from sqlalchemy import func
77# Local imports
8- from models import AsmInstruction , Noitip , Session , init_db
8+ import models
99
1010@contextmanager
1111def 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
2726def 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 :
You can’t perform that action at this time.
0 commit comments