예제 #1
0
파일: users.py 프로젝트: 0chk0/python
 def modify_password(self):
     """
     个人中心 - 修改密码
     :return:
     """
     _not_null_flag = False
     try:
         while not _not_null_flag:
             _new_password = input("输入新密码: ").strip()
             _confirm_password = input("再次输入确认密码:").strip()
             if not _new_password or not _confirm_password:
                 common.show_message("密码不能为空,请重新输入!", "ERROR")
                 continue
             if _new_password != _confirm_password:
                 common.show_message("两次输入密码不一致,请重新输入!", "NOTICE")
                 continue
             _not_null_flag = True
         self.password = _new_password
         _password = common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.update_user()
         common.show_message("密码修改成功!", "INFORMATIOM")
         return True
     except Exception as e:
         common.write_error_log(e)
         return False
예제 #2
0
파일: users.py 프로젝트: wushank/python
 def modify_password(self):
     """
     个人中心 - 修改密码
     :return:
     """
     _not_null_flag = False
     try:
         while not _not_null_flag:
             _new_password = input("输入新密码: ").strip()
             _confirm_password = input("再次输入确认密码:").strip()
             if not _new_password or not _confirm_password:
                 common.show_message("密码不能为空,请重新输入!", "ERROR")
                 continue
             if _new_password != _confirm_password:
                 common.show_message("两次输入密码不一致,请重新输入!", "NOTICE")
                 continue
             _not_null_flag = True
         self.password = _new_password
         _password = common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.update_user()
         common.show_message("密码修改成功!", "INFORMATIOM")
         return True
     except Exception as e:
         common.write_error_log(e)
         return False
예제 #3
0
파일: dbapi.py 프로젝트: 0chk0/python
def load_data_from_db(tabename):
    """
    从指定的数据表中获取所有数据,通过 json 方式将数据返回
    :param tabename: 数据文件名
    :return: 返回所有结果
    """
    try:
        with open(tabename, 'r+') as f:
            return json.load(f)
    except Exception as e:
        write_error_log(e)
예제 #4
0
파일: dbapi.py 프로젝트: wushank/python
def load_data_from_db(tabename):
    """
    从指定的数据表中获取所有数据,通过 json 方式将数据返回
    :param tabename: 数据文件名
    :return: 返回所有结果
    """
    try:
        with open(tabename, 'r+') as f:
            return json.load(f)
    except Exception as e:
        write_error_log(e)
예제 #5
0
파일: dbapi.py 프로젝트: 0chk0/python
def write_db_json(contant, filename):
    """
    将信息以 json 格式写入数据表文件(覆盖)
    :param contant: 写入的json数据内容
    :param filename: 要写入的文件名
    :return: 无返回结果
    """
    try:
        with open(filename, 'w+') as fw:
            fw.write(json.dumps(contant))
    except Exception as e:
        write_error_log(e)
예제 #6
0
파일: dbapi.py 프로젝트: wushank/python
def write_db_json(contant, filename):
    """
    将信息以 json 格式写入数据表文件(覆盖)
    :param contant: 写入的json数据内容
    :param filename: 要写入的文件名
    :return: 无返回结果
    """
    try:
        with open(filename, 'w+') as fw:
            fw.write(json.dumps(contant))
    except Exception as e:
        write_error_log(e)
예제 #7
0
파일: dbapi.py 프로젝트: 0chk0/python
def append_db_json(contant, filename):
    """
    将信息以 json 格式写入数据表文件(追加)
    :param contant: 要写入的 json 格式内容
    :param filename: 要写入的数据表文件名
    :return: 无返回
    """
    try:
        with open(filename, 'a+') as fa:
            fa.write(json.dumps(contant))
            fa.write("\n")
    except Exception as e:
        write_error_log(e)
예제 #8
0
파일: dbapi.py 프로젝트: wushank/python
def append_db_json(contant, filename):
    """
    将信息以 json 格式写入数据表文件(追加)
    :param contant: 要写入的 json 格式内容
    :param filename: 要写入的数据表文件名
    :return: 无返回
    """
    try:
        with open(filename, 'a+') as fa:
            fa.write(json.dumps(contant))
            fa.write("\n")
    except Exception as e:
        write_error_log(e)
예제 #9
0
def init_database():
    tables = list(settings.DATABASE['tables'].values())  # 数据表名称列表
    database = settings.DATABASE['dbpath']  # 数据表存放路径
    for _table in tables:
        # 如果表不存在
        if not os.path.exists(os.path.join(database, "{0}.db".format(_table))):
            print("Table {0}.db create successfull".format(_table))
            # 通过反射初始化数据表

            if hasattr(sys.modules[__name__], "init_db_{0}".format(_table)):
                init_func = getattr(sys.modules[__name__], "init_db_{0}".format(_table))
                init_func()
            else:
                common.write_error_log("init table {0} failed,no function init_db_{0} found".format(_table))
예제 #10
0
파일: dbapi.py 프로젝트: 0chk0/python
def load_statement_list(cardno):
    """
    从对账单中获取记录,
    :param cardno: 对账单文件
    :return: 返回一个列表
    """
    file = os.path.join(settings.REPORT_PATH, "statement_{0}".format(cardno))
    result_list = list()
    try:
        if os.path.isfile(file):
            with open(file, 'r+') as f:
                for line in f:
                    statement = json.loads(line)
                    result_list.append(statement)
        return result_list
    except Exception as e:
        write_error_log("dbapi > load_statement_list > {0}".format(e))
예제 #11
0
파일: dbapi.py 프로젝트: wushank/python
def load_statement_list(cardno):
    """
    从对账单中获取记录,
    :param cardno: 对账单文件
    :return: 返回一个列表
    """
    file = os.path.join(settings.REPORT_PATH, "statement_{0}".format(cardno))
    result_list = list()
    try:
        if os.path.isfile(file):
            with open(file, 'r+') as f:
                for line in f:
                    statement = json.loads(line)
                    result_list.append(statement)
        return result_list
    except Exception as e:
        write_error_log("dbapi > load_statement_list > {0}".format(e))
예제 #12
0
파일: dbapi.py 프로젝트: 0chk0/python
def load_bill_report(cardno, startdate, enddate):
    """
    从信用卡对账单中获取指定卡的对账信息数据, 获取某一个时间段内的数据
    :param enddate: 查询记录的结束日期
    :param startdate: 查询记录的开始日期
    :param cardno: 信用卡卡号
    :return: 信用卡对账单数据 ,返回结果为 list 数据类型
    """
    r_file = os.path.join(settings.REPORT_PATH, "report_bill")
    result = []
    try:
        with open(r_file, "r+") as f:
            for line in f:
                _record = json.loads(line)
                if _record["cardno"] == cardno:
                    if startdate <= _record["starttime"] <= enddate:
                        result.append(_record)
        return result
    except Exception as e:
        write_error_log(e)
예제 #13
0
파일: dbapi.py 프로젝트: wushank/python
def load_bill_report(cardno, startdate, enddate):
    """
    从信用卡对账单中获取指定卡的对账信息数据, 获取某一个时间段内的数据
    :param enddate: 查询记录的结束日期
    :param startdate: 查询记录的开始日期
    :param cardno: 信用卡卡号
    :return: 信用卡对账单数据 ,返回结果为 list 数据类型
    """
    r_file = os.path.join(settings.REPORT_PATH, "report_bill")
    result = []
    try:
        with open(r_file, "r+") as f:
            for line in f:
                _record = json.loads(line)
                if _record["cardno"] == cardno:
                    if startdate <= _record["starttime"] <= enddate:
                        result.append(_record)
        return result
    except Exception as e:
        write_error_log(e)
예제 #14
0
파일: dbapi.py 프로젝트: wushank/python
def load_shop_history(user, startdate, enddate):
    """
    查找报表记录中的指定用户的购物历史记录,将结果存入到列表中
    :param user:  用户名
    :param startdate: 开始日期
    :param enddate: 结束日期
    :return: 结果 dict_list
    """
    _file = os.path.join(settings.REPORT_PATH, "shopping_history")
    result = list()
    try:
        with open(_file, "r") as f:
            for line in f:
                _record = json.loads(line)
                # 如果找到指定用户记录
                if list(_record.keys())[0] == user:
                    if list(_record.values())[0]["time"] >= startdate <= enddate:
                        result.append(_record)
        return result
    except Exception as e:
        write_error_log("dbapi > load_shop_history > {0}".format(e))
예제 #15
0
파일: dbapi.py 프로젝트: 0chk0/python
def load_shop_history(user, startdate, enddate):
    """
    查找报表记录中的指定用户的购物历史记录,将结果存入到列表中
    :param user:  用户名
    :param startdate: 开始日期
    :param enddate: 结束日期
    :return: 结果 dict_list
    """
    _file = os.path.join(settings.REPORT_PATH, "shopping_history")
    result = list()
    try:
        with open(_file, "r") as f:
            for line in f:
                _record = json.loads(line)
                # 如果找到指定用户记录
                if list(_record.keys())[0] == user:
                    if list(_record.values()
                            )[0]["time"] >= startdate <= enddate:
                        result.append(_record)
        return result
    except Exception as e:
        write_error_log("dbapi > load_shop_history > {0}".format(e))
예제 #16
0
파일: users.py 프로젝트: 0chk0/python
 def update_user(self):
     """
     用户数据更新方法,用户修改信息、用户账户锁定、解锁等操作之后更新数据库文件
     :return:
     """
     try:
         '''
         _password = common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.dict_user[self.username]["islocked"] = self.islocked
         self.dict_user[self.username]["name"] = self.name
         self.dict_user[self.username]["mobile"] = self.mobile
         self.dict_user[self.username]["bindcard"] = self.bindcard
         self.dict_user[self.username]["isdel"] = self.isdel
         self.dict_user[self.username]["role"] = self.role
         '''
         # 写入数据库文件
         dbapi.write_db_json(self.dict_user, self.__database)
         return True
     except Exception as e:
         common.write_error_log(e)
         return False
예제 #17
0
파일: users.py 프로젝트: wushank/python
 def update_user(self):
     """
     用户数据更新方法,用户修改信息、用户账户锁定、解锁等操作之后更新数据库文件
     :return:
     """
     try:
         '''
         _password = common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.dict_user[self.username]["islocked"] = self.islocked
         self.dict_user[self.username]["name"] = self.name
         self.dict_user[self.username]["mobile"] = self.mobile
         self.dict_user[self.username]["bindcard"] = self.bindcard
         self.dict_user[self.username]["isdel"] = self.isdel
         self.dict_user[self.username]["role"] = self.role
         '''
         # 写入数据库文件
         dbapi.write_db_json(self.dict_user, self.__database)
         return True
     except Exception as e:
         common.write_error_log(e)
         return False