def create_tables(): database.connect() Category.drop_table(fail_silently=True) Thread.drop_table(fail_silently=True) Post.drop_table(fail_silently=True) Role.drop_table(fail_silently=True) Profile.drop_table(fail_silently=True) database.create_tables([Category, Thread, Post, Profile, Role]) database.close() if settings.DEBUG: setup_temp_data()
def on_finish(self): # save to database... browser_log = log( logLevel='INFO', logType='access', requestStatus=self.get_status(), requestType=self.request.method, requestURL=self.request.uri, requestIP=self.request.remote_ip, requestDuration=1000.0 * self.request.request_time() ) browser_log.save() if not database.is_closed(): database.close() return super(BaseHandler, self).on_finish()
def close_remind_button(bot, chat_id): try: closed_id = close(chat_id, '') for r in _get_remind(chat_id, closed_id): remind = f"⏰ Remind ({r['id']}): 📌 \"{r['remind_text']} on {datetime.datetime.strptime(r['remind_time'], DATETIME_FORMAT).strftime('%d.%m %H:%M')}\" marked as Done!✅" bot.send_message(chat_id=chat_id, text=remind) except: bot.send_message(chat_id=chat_id, text="Sorry, there is no remind(s) with such id(s) 😔")
def render(self,option): from conf.models import configOption from db import database flag = False try: database.connect() except: flag = True pass if configOption.select().where(configOption.name == option).exists(): if not flag: database.close() return configOption.get(configOption.name == option).value else: if not flag: database.close() return ''
def close_remind(bot, update, args): user_chat_id = update.message.chat_id if len(args) > 1: bot.send_message( chat_id=update.message.chat_id, text="Sorry, I can't close more than one remind at a time 😔") else: try: closed_id = close(user_chat_id, args) for r in _get_remind(user_chat_id, closed_id): remind = f"⏰ Remind ({r['id']}): 📌 \"{r['remind_text']} on {datetime.datetime.strptime(r['remind_time'], DATETIME_FORMAT).strftime('%d.%m %H:%M')}\" marked as Done!✅" bot.send_message(chat_id=update.message.chat_id, text=remind) except: bot.send_message( chat_id=update.message.chat_id, text="Sorry, there is no remind(s) with such id(s) 😔")
def teardown(exception): if not database.is_closed(): database.close()
def teardown(exception): if not database.is_closed(): database.close()
if __name__ == '__main__': import os from conf import ENVIRONMENT_VARIABLE # refer the setting modules os.environ[ENVIRONMENT_VARIABLE] = 'setting' print os.getcwd() finder = modelFinder() print finder.getInstalledModel() # create all table from db import database database.connect() for app, modelList in finder.getInstalledModel(): print app, modelList for name, model in modelList: print name try: database.create_tables([model]) # print app+' @ '+ name except Exception as e: print e finally: testFiledFinder = fieldFinder() testFiledFinder.getAllField(model) database.close()
def _db_close(e): if not database.is_closed(): database.close()
def after_request(): database.close()
def after_request(response): database.close() return response
def on_finish(self): if not database.is_closed(): database.close() return super(BaseHandler, self).on_finish()