Ejemplo n.º 1
0
def load_data_from_db(tablename):
    '''
    从指定的数据表中获取所有数据,通过json方式将数据返回
    :param tablename:数据文件名
    :return:返回所有结果
    '''
    try:
        with open(tablename, 'r+') as f:
            return json.load(f)
    except Exception as e:
        write_error_log(e)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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_shop_history > {0}".format(e))
Ejemplo n.º 5
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))
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def load_shop_histroy(user, startdate, enddate):
    '''
    从信用卡对账单中获取指定的对账信息数据,获取某一个时间段内的数据
    :param enddate:查询记录的结束日期
    :param startdate:查询记录的开始日期
    :param user:用户名
    :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 startdate <= list(
                            _record.values())[0]["time"] <= enddate:
                        result.append(_record)

        return result
    except Exception as e:
        write_error_log("dbapi > load_shop_history > {0}".format(e))