コード例 #1
0
def acc_auth(account, password):
    '''
    account auth func
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , retun the account object, otherwise ,return None
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" % (db_path, account)
    # print(account_file)
    if os.path.isfile(account_file):
        with open(account_file, 'r') as f:
            account_data = json.load(f)
            if account_data['password'] == password:
                exp_time_stamp = datetime.datetime.strptime(
                    account_data['expire_date'], "%Y-%m-%d")
                status = account_data['status']
                if datetime.datetime.now() > exp_time_stamp:
                    print(
                        "\033[31;1mAccount [%s] has expired,please contact the admin to get a new card!\033[0m"
                        % account)
                elif status == 0 or status == 8:  # 状态正常,或者为admin
                    return account_data
                else:
                    print(
                        "Account \033[31;1m%s\033[0m] status is abnormal,please contact the admin."
                    )
            else:
                print("\033[31;1mAccount ID or password is incorrect!\033[0m")
    else:
        print("\033[31;1mAccount [%s] does not exist!\033[0m" % account)
コード例 #2
0
ファイル: create.py プロジェクト: ddoplayer2012/py
def file_db_insert(table_name, data_row):
    """
    验证数据完整性,验证通过后将行数据附加到文件末尾
    :param table_name: 要写入的表名
    :param data_row: 要写入的行数据元组
    :return: 无
    """
    db_path = db_handler.db_handler(config.DATABASE)
    db_file = "%s/%s.db" % (db_path, table_name)

    if os.path.isfile(db_file):
        with open(db_file, "r+", encoding="utf-8") as f:
            flag = True
            max_value = 0
            for line in f:
                row = line.strip().split(',')
                columns_and_values = dict(
                    zip(config.TABLE_COLUMNS[table_name], data_row))
                if not check.check_primary_key(table_name, row,
                                               columns_and_values):
                    flag = False
                    break
                max_value = check.check_auto_increment(table_name, row,
                                                       columns_and_values)
                if not max_value:
                    flag = False
                    break
            if flag:
                f.writelines(
                    insert_auto_increment_column(table_name, max_value,
                                                 data_row))
                print("已插入1行")
コード例 #3
0
ファイル: auth.py プロジェクト: NoSongmaster/home_project
def acc_auth2(account, password):
    '''
    优化版认证接口
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , retun the account object, otherwise ,return None

    '''
    db_api = db_handler.db_handler(
    )  #调用dbhandle.db_handler()。这里返回的是file_execute
    data = db_api("select * from accounts where account=%s" %
                  account)  #调用file_execute(传入sql)
    if data is False: return
    if data['password'] == password:  #验证用户输入的密码
        exp_time_stamp = time.mktime(
            time.strptime(data['expire_date'], "%Y-%m-%d"))  #验证本地时间和信用卡过去时间
        if time.time() > exp_time_stamp:  #判断信用卡是否过期
            print(
                "\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m"
                % account)  #打印过期信息
        else:  # passed the authentication
            return data  #返回获取到的用户数据
    else:
        print("\033[31;1mAccount ID or password is incorrect!\033[0m"
              )  #打印用户名或密码错误
コード例 #4
0
ファイル: auth.py プロジェクト: boundshunter/da-new-s4-code
def account_modify():
    '''
    修改账户信息
    :return:
    '''
    retry_count = 0
    items = ['enroll_date','password','id','credit','status','balance','expire_date','pay_day']
    while True:
        account = input("输入要修改的账户ID>>>:")
        acc_data = check_account(account)   # 判断用户可用性
        db_path = db_handler.db_handler(settings.DATABASE)  # settings.DATABASE = conn_parms
        account_file = "%s/%s.json" % (db_path, account)
        if acc_data:  # Not None
            #  用户存在显示用户信息
            display_account_info(acc_data)
            # print(type(acc_data))

            while True:
                input_item = input("请选择您要修改的项目>>>:")
                input_value = input("请输入您要修改的值>>>:")
                # 修改账户信息
                acc_data[input_item] = input_value
                account_data = acc_data
                print("\033[31;1m您已将账户ID为[%s] 中项目 [%s] 值修改为 [%s] !\033[0m" % (account,input_item,input_value))
                # 修改数据写回用户ID数据文件
                accounts.dump_account(account_data)
                return True
        else:
            print("您要修改的用户 [%s] 不存在!" % account)
            return True
コード例 #5
0
ファイル: auth.py プロジェクト: boundshunter/da-new-s4-code
def ck_acc_data(account):
    '''
    检查用户是否存在,不做用户权限判断
    :param account:用户ID
    :return: account_data
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" % (db_path, account)

    if os.path.isfile(account_file):
        with open(account_file,'r') as f:
            account_data = json.load(f)
            status = account_data['status']
            # if status == 8:
            #     print("权限不足,账户[%s]为管理员,无法查看." % account_data['id'])
            #     return False

            exp_time_stamp = datetime.datetime.strptime(account_data['expire_date'],"%Y-%m-%d")
            curr_time = datetime.datetime.now()
            if  curr_time > exp_time_stamp:
                print("账户 [%s] 已过期!" % account)
                return False
            else:
                return account_data
    else:
        return False
コード例 #6
0
ファイル: auth.py プロジェクト: gushiren2012/s16
def acc_auth(account,password):
    '''
    account auth func
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , retun the account object, otherwise ,return None
    '''
    #连接数据库
    db_path = db_handler.db_handler(settings.DATABASE)
    #生成用户文件
    account_file = "%s/%s.json" %(db_path,account)
    print(account_file)
    #判断account_file是否文件
    if os.path.isfile(account_file):
        with open(account_file,'r') as f:#打开读取
            account_data = json.load(f)#重新加载数据
            if account_data['password'] == password:#判断密码是否正确
                exp_time_stamp = time.mktime(time.strptime(account_data['expire_date'], "%Y-%m-%d"))#判断过期时间
                if time.time() >exp_time_stamp:#判断如果用户账户时间过期就返回过期信息提示换新卡
                    print("\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m" % account)
                else: #passed the authentication 如果没过期就返回账户数据
                    return  account_data
            else:#如果密码不正确则提示密码错误
                print("\033[31;1mAccount ID or password is incorrect!\033[0m")
    else:#如果不是文件,则提示用户文件不存在
        print("\033[31;1mAccount [%s] does not exist!\033[0m" % account)
コード例 #7
0
ファイル: main.py プロジェクト: wangyufu/host_manage
def user_host(user_id):
    sql = db_handler.db_handler()
    data = sql(
        'select', 'select * from user_host_relational \
        left join host on user_host_relational.host_id = host.id \
        where user_id=%d' % user_id)
    return data
コード例 #8
0
ファイル: manager.py プロジェクト: caiyongtian/atm
def add_account():
    acc_dict = {}
    flag = True
    while flag:
        print('欢迎进入新用户注册界面'.center(50, '-'))
        acc_dict['name'] = input('请输入持卡人姓名: ')
        acc_dict['password'] = input('请输入密码: ')
        acc_dict['id'] = random.randint(1, 6),
        acc_dict['enroll_date'] = time.asctime()
        two_year_datetime = datetime.datetime.now() + datetime.timedelta(
            days=730)
        acc_dict['expire_date'] = time.ctime(
            time.mktime(two_year_datetime.timetuple()))
        acc_dict['status'] = 0

        db_path = db_handler.db_handler(setting.DATABASE)

        if os.path.exists('%s.json' % os.path.join(db_path, acc_dict['id'])):
            print('用户名重复,请重新注册')
            continue
        else:
            accounts.dump_account(acc_dict)
            print('您注册的用户信息如下'.center(50, '-'))
            print('''
            持卡人姓名:    %s
            卡号:          %d
            注册时间:      %s
            过期时间:      %s
            用户状态:      %d
            ''') % (acc_dict['name'], acc_dict['id'], acc_dict['enroll_date'],
                    acc_dict['expire_date'], acc_dict['status'])
    return
コード例 #9
0
def acc_auth2(account, password):
    '''
    优化版认证接口
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , retun the account object, otherwise ,return None

    '''
    db_api = db_handler.db_handler()
    data = db_api("select_course_system * from accounts where account=%s" %
                  account)

    if data['status'] == 1:
        print('sorry! 您的账户已被冻结,请联系管理员。')
        exit('bye!')
    if data['password'] == password:
        exp_time_stamp = time.mktime(
            time.strptime(data['expire_date'], "%Y-%m-%d"))
        if time.time() > exp_time_stamp:
            print(
                "\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m"
                % account)
        else:  # passed the authentication
            return data
    else:
        print("\033[31;1mAccount ID or password is incorrect!\033[0m")
コード例 #10
0
ファイル: auth.py プロジェクト: salmon5/python-homework
def acc_auth(account, password):
    '''
    用户验证:账户是否存在,密码是否过期等
    :param account:
    :param password:
    :return:
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" % (db_path, account)

    if os.path.isfile(account_file):
        with open(account_file, 'r') as f:
            account_data = json.load(f)
            if account_data['password'] == password:
                exp_time_stamp = time.mktime(
                    time.strptime(account_data['expire_date'],
                                  "%Y-%m-%d"))  #把字符串转换成时间戳
                if time.time() > exp_time_stamp:
                    print(
                        "\033[031;1mAccount [%s] has expired,please contact the back to get as new card!\033[0m "
                        % account)
                else:
                    return account_data
            else:
                print("\033[031;1mAccount Id or password is incorrect!\033[0m")
    else:
        print("\033[031;1mAccount [%s] dose not exist!\033[0m" % account)
コード例 #11
0
ファイル: main.py プロジェクト: ChacoLv/python-oldboy
 def acc_auth(self):
     while True:
         data = self.request.recv(1024)  #接收客户端传递过来的用户认证数据
         user_info = json.loads(data.decode())
         username = user_info["username"]  #客户端传递过来的用户名
         hash_pass = user_info["password"]  #客户端传递过来的用户密码,已被md5 hash
         db_path = db_handler.db_handler()  #数据文件
         account_file = "%s/%s.json" % (db_path, username)
         if os.path.isfile(account_file):
             with open(account_file, "r") as f:
                 account_info = json.load(f)
                 password = account_info["password"]
                 h_pass = hashlib.md5(password.encode()).hexdigest(
                 )  #服务器端根据客户端提供的账号,查询密码,并进行hash
                 if hash_pass == h_pass:
                     response = "200 ack"  #认证成功,设置回应代码
                 else:
                     response = "401 password error,please retry"  #认证失败,密码错误
         else:
             response = "402 user does not exist,please retry"  #认证失败,账号不存在
         if response.startswith("200"):  #如果认证成功,则发送用户账号信息给客户端,客户端可以查看账号信息
             user_home_dir = home_dir_handler.home_dir_handler(
                 username)  #认证成功后,获取用户ftp家目录
             account_info["current_dir"] = user_home_dir  #修改用户库中当前目录信息
             dir_list = os.listdir(user_home_dir)  #获取用户当前目录文件清单
             account_info["dir_list"] = []
             for i in dir_list:
                 account_info["dir_list"].append(i)  #将用户目录清单写入用户信息中
             self.request.send(json.dumps(account_info).encode())
             with open(account_file, "w") as f:
                 f.write(json.dumps(account_info))
             return True
         else:  #如果认证失败,则发送错误代码给客户端,客户端接收并查看
             self.request.send(response.encode())
             return False
コード例 #12
0
ファイル: auth.py プロジェクト: gaohaha435/pyprogram
def acc_auth(user_data,account,password):
    '''
    文件认证接口
    :param account: 需认证的账号
    :param password: 需认证的密码
    :return: 认证通过返回账号对象,认证不通过返回null
    '''

    db_path = db_handler.db_handler(user_data)
    account_file = "%s/%s.json" %(db_path,account)
    #print(account_file)
    if os.path.isfile(account_file):
        with open(account_file,'r') as f:
            account_data = json.load(f)
            if account_data['password'] == password:
                exp_time_stamp = time.mktime(time.strptime(account_data['expire_date'], "%Y-%m-%d"))
                if time.time() >exp_time_stamp:
                    print("\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m" % account)
                else: #passed the authentication
                    return  account_data
            else:
                print("\033[31;1mAccount ID or password is incorrect!\033[0m")
    else:
        while True:
            account_bar = input("\033[31;1mAccount [%s] 账户不存在是否立即注册!(y,n)\033[0m" % account)
            if account_bar == "y":
                accounts.register(user_data)
                exit()
            elif account_bar == "n":
                exit()
            else:
                print("\033[31;1mAccount [%s] 账户不存在是否立即注册!(y,n)\033[0m" % account)
コード例 #13
0
def dump_account(account_data):
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = '%s/%s.json' % (db_path, account_data['id'])
    with open(account_file, 'w') as f:
        acc_data = json.dump(account_data, f)

    return True
コード例 #14
0
ファイル: auth.py プロジェクト: GaoFuhong/python-code
def acc_auth(account, password):
    '''
    账户验证函数
    :param account:验证账户的账号
    :param passwprd:验证密码
    :return:如果登录成功,返回账户;否则,返回None
    '''
    db_path = db_handler.db_handler(settings.DATABASE)  #传数据库的信息
    account_file = "%s/%s.json" % (db_path, account)  #将账户文件的内容赋值给account_file
    print(account_file)
    if os.path.isfile(account_file):
        with open(account_file, 'r') as f:  #打开文件
            account_data = json.load(f)
            if account_data['password'] == password:  #密码正确
                exp_time_stamp = time.mktime(
                    time.strptime(account_data['expire_date'],
                                  "%Y-%m-%d"))  #判断用户是否已过期
                if time.time() > exp_time_stamp:  #过期
                    print(
                        "\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m"
                        % account)
                else:  # 通过验证
                    return account_data
            else:  #没过期
                print("\033[31;1mAccount ID or password is incorrect!\033[0m")
    else:
        print("\033[31;1mAccount [%s] does not exist!\033[0m" % account)
コード例 #15
0
def acc_check(account):
    '''
    查找帐号是否存在
    :param account: credit account number
    :return: 帐号存在返回真,否则返回假
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" % (db_path, account)
    if os.path.isfile(account_file):
        with open(account_file, 'r') as f:
            account_data = json.load(f)
            status = account_data['status']
            # if status == 8:  # 帐户为管理员
            #     print("\033[31;1mGet account [%s] info pemission denied!\033[0m" % account)
            #     return False

            exp_time_stamp = datetime.datetime.strptime(
                account_data['expire_date'], "%Y-%m-%d")
            if datetime.datetime.now() > exp_time_stamp:
                print("\033[31;1mAccount [%s] has expired!\033[0m" % account)
                return False
            else:
                return account_data
    else:
        return False
コード例 #16
0
ファイル: auth.py プロジェクト: darksugar/pythonProjects
def acc_auth(account, password, user_type):
    '''
    优化版认证接口
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , retun the account object, otherwise ,return None
    '''
    db_api = db_handler.db_handler()
    if user_type == "T":
        account_data = db_api.teacher_auth(account)
    else:
        account_data = db_api.student_auth(account)
    # print(account_data)
    if account_data:
        if account_data.password == password:
            exp_time_stamp = time.mktime(
                time.strptime(account_data.expire_date, "%Y%m%d"))
            if account_data.status == 0:
                if time.time() > exp_time_stamp:
                    print(
                        "\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m"
                        % account)
                else:  # passed the authentication
                    return account_data
            else:
                print("\033[31;1mThe Account is frozen!!!\033[0m")
        else:
            print("\033[31;1mAccount ID or password is incorrect!\033[0m")
コード例 #17
0
def acc_check(account):
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" % (db_path, account)
    if os.path.isfile(account_file):
        with open(account_file, 'r') as f:
            account_data = json.load(f)
            return account_data
コード例 #18
0
ファイル: auth.py プロジェクト: doraqiqi/day5
def acc_auth(username, password, user_data_dic):

    db_path = db_handler.db_handler()  #调用数据库判断模块获取数据库地址
    db_account = "%s\\accounts\\%s.json" % (db_path, username
                                            )  #使用数据库地址调取数据库中相应的账户数据

    print("该用户数据文件路径,%s" % db_account)
    if os.path.exists(db_account):
        # with open(db_account,"r") as f:
        #     print(f.read())
        f = open(db_account, "r")
        account_data_dic = json.loads(f.read())  #这是账户数据,以json读取的字典形式呈现
        print("该用户数据文件内容", account_data_dic)
        print("这是临时用户数据,", user_data_dic)

        if account_data_dic["username"] == username and account_data_dic[
                "password"] == password:
            print("登录成功")
            user_data_dic["is_logined"] = True
            user_data_dic["user_data"] = account_data_dic
            print("acc_auth登录成功后的user_data_dic", user_data_dic)
            return user_data_dic

        else:
            print("错误的用户名或密码")
    else:
        print("错误的用户名或密码")
コード例 #19
0
def acc_auth(account, password):
    '''
    account auth func
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , retun the account object, otherwise ,return None
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" % (db_path, account)
    print(account_file)
    if os.path.isfile(account_file):
        with open(account_file, 'r') as f:
            account_data = json.load(f)
            if account_data['password'] == password:
                exp_time_stamp = time.mktime(
                    time.strptime(account_data['expire_date'], "%Y-%m-%d"))
                if time.time() > exp_time_stamp:
                    print(
                        "\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m"
                        % account)
                else:  #passed the authentication
                    return account_data
            else:
                print("\033[31;1mAccount ID or password is incorrect!\033[0m")
    else:
        print("\033[31;1mAccount [%s] does not exist!\033[0m" % account)
コード例 #20
0
ファイル: search.py プロジェクト: ddoplayer2012/py
def file_db_format_output(table_name, table_columns, query_criteria):
    """
    格式化输出文件数据表的查询结果
    :param table_name: 表名
    :param table_columns: 要输出的列元组
    :param query_criteria: 查询条件,字典
    :return: 
    """
    db_path = db_handler.db_handler(config.DATABASE)
    db_file = "%s/%s.db" % (db_path, table_name)

    if os.path.isfile(db_file):
        output_row_title(table_name, table_columns)
        output_row_line(table_name, table_columns)
        row_count = 0
        with open(db_file, 'r', encoding="utf-8") as f:
            for line in f:
                # 去掉空格和换行符,以逗号分割为一个列表
                row = line.strip().split(',')
                if query_criteria:
                    if check.is_dml_row(table_name, row, query_criteria):
                        output_rows(table_name, table_columns, row)
                        row_count += 1
                else:
                    output_rows(table_name, table_columns, row)
                    row_count += 1
        if row_count > 0:
            output_row_line(table_name, table_columns)
        print("已查询%s行" % row_count)
コード例 #21
0
def register(user_data):
    '''
    This function is to register users
    :return:
    '''

    dict = settings.ACCOUNT_TYPE
    account = input('请输入您要注册的username:'******'请输入您要注册的password:'******'username': account,
            'password': password,
            'role': 'user'
        })
    elif user_data["account_role"] == "admin":
        dict.update({
            'username': account,
            'password': password,
            'role': 'admin'
        })

    db_path = db_handler.db_handler(user_data)
    account_file = "%s/%s.json" % (db_path, account)
    print(account_file)

    with open(account_file, 'w', encoding="utf-8") as f:
        json.dump(dict, f)
コード例 #22
0
def acc_auth(account, password):
    """
    账户验证函数
    :param account: 用户输入的帐号
    :param password: 用户输入的密码
    :return:
    """ ""
    db_path = db_handler.db_handler(
        settings.DATABASE)  # db_path是保存用户信息的文件所在目录的信息
    account_file = "%s/%s.json" % (db_path, account)  # 目录加上文件名
    if os.path.isfile(account_file):
        with open(account_file, "r", encoding="utf-8") as f:
            account_data = json.load(f)  # 通过反序列化取出用户所有的信息
            if account_data["password"] == password:

                #  将字符串类型的日期时间转换成日期时间类型
                exp_time_stamp = datetime.datetime.strptime(
                    account_data['expire_date'], "%Y-%m-%d")
                status = account_data['status']
                if datetime.datetime.now() > exp_time_stamp:
                    print("帐号%s的信用卡已过期,请申请新的信用卡" % account)
                elif status == 0 or status == 8:  # 状态正常,或为管理员
                    return account_data  # account_data是用户详细信息
                else:
                    print("帐号%s状态异常" % account)
            else:
                print("帐号或密码错误")
    else:
        print("帐号%s不存在" % account)
コード例 #23
0
def acc_check(account):
    """
    查看账户是否存在
    :param account: 用户名
    :return: 帐号存在返回用户信息,帐号不存在或帐号过期则返回False
    """ ""
    db_path = db_handler.db_handler(
        settings.DATABASE)  # db_path是保存用户信息的文件所在目录的信息
    account_file = "%s/%s.json" % (db_path, account)  # 目录加上文件名

    if os.path.isfile(account_file):
        with open(account_file, "r", encoding="utf-8") as f:
            account_data = json.load(f)

            #  将字符串类型的日期时间转换成日期时间类型
            exp_time_stamp = datetime.datetime.strptime(
                account_data['expire_date'], "%Y-%m-%d")

            if datetime.datetime.now() > exp_time_stamp:
                print("\033[31;1m帐号[%s]已过期!\033[0m" % account)
                return False
            else:
                return account_data
    else:
        return False
コード例 #24
0
ファイル: main.py プロジェクト: boundshunter/da-new-s4-code
def get_all_bills():
    '''
    获取所有用户账单信息
    :return:
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    # 获取路径,目录,文件名称
    for root, dirs, files in os.walk(db_path):
        print("root:%s, dirs:%s files:%s" % (root, dirs, files))
        for f in files:
            # 判断是否存在.json结尾的文件
            if os.path.splitext(f)[1] == ".json":
                # 获取账户ID
                account_id = os.path.splitext(f)[0]  # 帐户id
                # account_file = "%s/%s.json" % (db_path, account_id)
                # account_data = auth.check_account(account_id)  # 获取用户信息
                account_data = auth.ck_acc_data(account_id)
                # 判断用户权限是否为管理员
                if account_data:
                    status = account_data['status']
                    # print(status)
                    print("Account bill:".center(50, "-"))

                    # 除了管理员,普通帐户都应该出帐单,即使帐户禁用
                    if status != 8:
                        # print("status != 8 ",account_id)
                        auth.display_account_info(account_data)
                        get_user_bill(account_id)  # 获取帐单
                        print("End".center(50, "-"))
    return True
コード例 #25
0
ファイル: main.py プロジェクト: boundshunter/da-new-s4-code
def display_bills(acc_data):
    '''
    显示用户账单
    :param acc_data:
    :return:
    '''
    check_date = input(
        "请输入查询日期 \033[31;1meg:[2018-02] \033[0m>>:".strip())  #输入查询日期年月
    log_path = db_handler.db_handler(settings.LOG_DATABASE)  # 日志路径
    bill_file = "%s/%s.bills" % (log_path, acc_data['account_id'])  # 日志文件路径
    print(bill_file)
    # 判断账单文件是否为空
    if os.path.isfile(bill_file):
        print("账户 [\033[32;1m%s\033[0m] 账单:".center(60, '-') %
              acc_data["account_id"])
        with open(bill_file, 'r') as f:
            for bill in f:
                # print("for bills:",bill)
                bill_date = bill.split(' ')[1]  # 取账单月份
                # print(bill_date)

                # 核对查询月份,打印相应账单信息
                if check_date == bill_date:
                    print("\033[33;1m%s\033[0m" % bill.strip())

        log_type = "transaction"
        # 传入account_id 转换成int型,比较大小,获取用户操作日志
        # 根据查询,显示账单
        logger.show_log(int(acc_data['account_id']), log_type, check_date)
        return True

    else:
        print("你的账号[%s]不存在账单" % acc_data['account_id'])
        return True
コード例 #26
0
ファイル: main.py プロジェクト: boundshunter/da-new-s4-code
def get_user_bill(account_id):
    '''
    获取用户账单
    :param account_id:
    :return:
    '''
    i = datetime.datetime.now()  # 当前时间
    year_month = "%s" % (datetime.datetime.strftime(i, "%Y-%m"))  # 帐单年月
    account_data = accounts.load_balance(account_id)  # 获取帐户信息
    balance = account_data["balance"]  # 可用额度
    credit = account_data["credit"]  # 信用额度
    if i.day != settings.BILL_DAY:
        print("\033[31;1mToday is not the bill generation day!\033[0m")
        # return    # 此处为了演示,先注释

    # 判断额度,判定是否提示还款
    if balance >= credit:
        repay_amount = 0
        bill_info = "Account [\033[32;1m%s\033[0m] needn't to repay." % account_id
    else:
        repay_amount = credit - balance
        bill_info = "Account [\033[32;1m%s\033[0m] need to repay [\033[33;1m%s\033[0m]" \
                    % (account_id, repay_amount)

    print(bill_info)
    log_path = db_handler.db_handler(settings.LOG_DATABASE)
    bill_log = "%s/%s.bills" % (log_path, account_id)
    # 记录账单信息
    with open(bill_log, "a+") as f:
        f.write("bill_date: %s account_id: %s need_repay: %d\n" %
                (year_month, account_id, repay_amount))
コード例 #27
0
ファイル: remove.py プロジェクト: ddoplayer2012/py
def file_db_delete(table_name, query_criteria):
    """
    删除表中的数据
    :param table_name: 表名
    :param query_criteria: 查询条件
    :return: 无
    """
    db_path = db_handler.db_handler(config.DATABASE)
    db_file = "%s/%s.db" % (db_path, table_name)
    db_file_tmp = "%s/%s.tmp" % (db_path, table_name)

    if os.path.isfile(db_file):
        count = 0
        with open(db_file, "r",
                  encoding="utf-8") as file, open(db_file_tmp,
                                                  "w",
                                                  encoding="utf-8") as tmp:
            for line in file:
                row = line.strip().split(',')
                if check.is_dml_row(table_name, row, query_criteria):
                    count += 1
                    continue
                else:
                    tmp.writelines(line)
        os.remove(db_file)
        os.rename(db_file_tmp, db_file)
        print("已删除%d行" % count)
コード例 #28
0
def pay_check(acc_data):
    """
    查询帐单详情
    :param acc_data:
    :return:
    """
    bill_date = input("Please input the date you will query "
                      "like [\033[32;1m2016-12\033[0m]>>>").strip()
    log_path = db_handler.db_handler(settings.LOG_DATABASE)
    bill_log = "%s/%s.bills" % (log_path, acc_data['account_id'])
    if not os.path.exists(bill_log):
        print("Account [\033[32;1m%s\033[0m] is no bills." %
              acc_data["account_id"])
        return

    print("Account [\033[32;1m%s\033[0m] bills:" % acc_data["account_id"])
    print("-".center(50, "-"))
    with open(bill_log, "r") as f:
        for bill in f:
            print(bill)
            b_date = bill.split(" ")[0]  # 帐单月份
            if bill_date == b_date:
                print("\033[33;1m%s\033[0m" % bill.strip())

    log_type = "transaction"
    print("Account [\033[32;1m%s\033[0m] history log:" %
          acc_data["account_id"])
    logger.show_log(acc_data['account_id'], log_type, bill_date)
コード例 #29
0
def acc_auth2(account, password):
    '''
    优化版认证接口
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , retun the account object, otherwise ,return None

    '''

    # 读取json获取指定用户的账户信息
    # 一个账户一个账户名.json文件
    db_api = db_handler.db_handler()

    data = db_api("select * from accounts where account=%s" % account)

    if data['password'] == password:
        exp_time_stamp = time.mktime(
            time.strptime(data['expire_date'], "%Y-%m-%d"))
        if time.time() > exp_time_stamp:
            print(
                "\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m"
                % account)
        else:  # passed the authentication
            return data
    else:
        print("\033[31;1mAccount ID or password is incorrect!\033[0m")
コード例 #30
0
def get_bill(user_data):
    '''
    用户生产账单
    :param account_id:
    :return:
    '''
    i = datetime.datetime.now()  #当前时间
    year_month = "%s-%s" % (i.year, i.month)
    account_id = user_data["account_id"]
    account_data = accounts.load_current_balance(account_id)
    balance = account_data["balance"]  #可用额度
    credit = account_data["credit"]  #信用额度
    if i.day != settings.BILL_DAY:
        print("\033[31;1maccountant bill date is 25 by the month.\033[0m")

    if balance >= credit:
        repay_amount = 0
        bill_info = "Account [\033[32;1m%s\033[0m] needn't to repay." % account_id
    else:
        repay_amount = credit - balance
        bill_info =  "Account [\033[32;1m%s\033[0m] need to repay [\033[33;1m%s\033[0m]" \
                    % (account_id, repay_amount)

    print(bill_info)

    bill_path = db_handler.db_handler(settings.LOG_DATABASE)
    bill_log = "%s/log/%s.bills" % (bill_path, account_id)
    with open(bill_log, "a+") as f:
        f.write("bill_date: %s account_id: %s need_repay: %d\n" %
                (year_month, account_id, repay_amount))
コード例 #31
0
ファイル: accounts.py プロジェクト: BruceBee/py_training
def load_current_balance(account_id):
    '''
    return account balance and other basic info
    :param account_id:
    :return:
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" %(db_path,account_id)
    with open(account_file) as f:
        acc_data = json.load(f)
        return  acc_data
コード例 #32
0
ファイル: accounts.py プロジェクト: BruceBee/py_training
def dump_account(account_data):
    '''
    after updated transaction or account data , dump it back to file db
    :param account_data:
    :return:
    '''
    db_path = db_handler.db_handler(settings.DATABASE)
    account_file = "%s/%s.json" %(db_path,account_data['id'])
    with open(account_file, 'w') as f:
        acc_data = json.dump(account_data,f)

    return True
コード例 #33
0
ファイル: auth.py プロジェクト: kHRYSTAL/StartLearningPython
def acc_auth2(account, password):
    """
    优化版认证接口
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication, return the account object, otherwise, return None
    """
    db_api = db_handler.db_handler()
    data = db_api("select * from accounts where account=%s" % account)
    if data['password'] == password:
        exp_time_stamp = time.mktime(time.strptime(data['expire_data'], "%Y-%m-%d"))
        if time.time() > exp_time_stamp:
            print("\033[31;1mAccount [%s] has expired,please contact the back to get a new card!\033[0m" % account)
        else:  # passed the authentication
            return data
    else:
        print("\033[31;1mAccount ID or password is incorrect!\033[0m")
コード例 #34
0
ファイル: auth.py プロジェクト: hawahe/leran_frank
def acc_auth(account,password):
    '''
    account auth func
    :param account: credit account number
    :param password: credit card password
    :return: if passed the authentication , return the account object, otherwise, return None
    '''
    db_path = db_handler.db_handler(setting.DATABASE)
    account_file = "%s/%s.jason" %(db_path,account)
    print(account_file)
    if os.path.isfile(account_file):
        with open(account_file,'r') as f:
            account_data = json.load(f)
            if account_data['password'] == password:
                exp_time_stamp = time.mktime(time.strptime(account_data['expire_data'],"%Y-%m-%d"))
                if time.time() > exp_time_stamp:
                    print("Account [%s] has expired, please contact the back to get a new account" %account)
                else:
                    return account_data
            else:
                print("Account ID or password is incorrect!")
    else:
        print("Account [%s] does not exist!" % account)