def init_data(): print('init_data...') from database.db_config import db_session from database.tbl_admin import TblAdmin user = TblAdmin() user.name = "__MAIL__" user.value = "*****@*****.**" user.type = 1 email = TblAdmin() email.name = "__MAILPASSWORD__" email.value = "xxxxxxxxxx" email.type = 1 user_exist = db_session.query( TblAdmin.name).filter(TblAdmin.name == user.name).first() if user_exist is None: db_session.add(user) mail_exist = db_session.query( TblAdmin.name).filter(TblAdmin.name == email.name).first() if mail_exist is None: db_session.add(email) db_session.commit() db_session.close() print("done!")
def add_to_db(jid, jdate, jvalue, jper): add_jj = False add_sum = False jj = db_session.query(TblJijin).filter(TblJijin.jid == jid, TblJijin.jdate == jdate).first() if jj is None: add_jj = True jj = TblJijin() jj.jid = jid jj.jdate = jdate jj.jvalue = jvalue jsum = db_session.query(TblSum).filter(TblSum.jid == jid, TblSum.jdate == jdate).first() if jsum is None: add_sum = True jsum = TblSum() jsum.jid = jid jsum.jdate = jdate jsum.jper = jper try: jsum.jinc = 1 if float(jper) > 0 else 0 if int(jper) == 0 else -1 except Exception as e: jsum.jinc = 0 try: if add_jj: db_session.add(jj) if add_sum: db_session.add(jsum) db_session.commit() except Exception as e: db_session.rollback() db_session.close()
def init_admin(): from database.tbl_admin import TblAdmin user = TblAdmin() user.name = "__MAIL__" user.value = "*****@*****.**" user.type = 1 db_session.add(user) db_session.commit() db_session.close()
def init_admin(): from database.tbl_admin import TblAdmin user = TblAdmin() user.name = "appversion" user.value = "1.0" user.type = 1 db_session.add(user) db_session.commit() db_session.close()
def init_version(): from database.tbl_admin import TblAdmin version = TblAdmin() version.name = "appversion" version.value = "1.0" version.type = 1 db_session.add(version) db_session.commit() db_session.close()
def init_user(): from database.tbl_account import TblAccount account = TblAccount() account.username = "******" account.password = MD5("111111") account.email = "*****@*****.**" account.userstate = 0 account.userrole = 0 db_session.add(account) db_session.commit() db_session.close()
def clear_history(days): clear_date = DatetimeManage.get_days_ago(days) try: db_session.query(TblBrowsingHistory).filter( TblBrowsingHistory.browsing_date <= clear_date).delete() db_session.commit() db_session.close() weblog.info("db data history clear...") except Exception as e: print(e) weblog.exception("data history error. {}".format(e))
def init_user(): from database.tbl_account import TblAccount account = TblAccount() account.loginname = "youth303" account.nickname = u"青春" account.password = MD5("303303") account.email = "" account.userstate = 0 account.userrole = 2 db_session.add(account) db_session.commit() db_session.close()
def init_account(): print('init one account...') from database.db_config import db_session from database.tbl_account import TblAccount from method.data_encode import MD5 account = TblAccount() account.username = "******" account.password = MD5("123456") account.userrole = 0 account.email = "*****@*****.**" db_session.add(account) db_session.commit() db_session.close() print("add ok")
def clear_old_data(): pass data_clear_date = DatetimeManage.get_days_ago(365) try: pass db_session.query(TblJijin).filter( TblJijin.jdate <= data_clear_date).delete() db_session.query(TblSum).filter( TblSum.jdate <= data_clear_date).delete() db_session.commit() db_session.close() except Exception as e: print(e) weblog.exception("data TblJijin/TblSum error. {}".format(e))
def init_account(): print('init one account...') from database.db_config import db_session from database.tbl_account import TblAccount from method.data_encode import MD5 account = TblAccount() account.loginname = "Tornado" account.nickname = u"飞影" account.password = MD5("dgj_039103") account.userrole = 0 account.userstate = 0 account.email = "*****@*****.**" db_session.add(account) db_session.commit() db_session.close() print("add ok")
def init_info(): from database.db_config import db_session from database.tbl_admin import TblAdmin user = TblAdmin() user.name = "appinfo" user.value = "1.0" user.type = 1 user_exist = db_session.query(TblAdmin.name).filter(TblAdmin.name == user.name).first() if user_exist is None: db_session.add(user) user = TblAdmin() user.name = "appversion" user.value = "1.0" user.type = 1 mail_exist = db_session.query(TblAdmin.name).filter(TblAdmin.name == user.name).first() if mail_exist is None: db_session.add(user) db_session.commit() db_session.close()
def save(self): db_session.add(self) db_session.commit() db_session.close()