예제 #1
0
def repay(acc_data):
    '''
    print current balance and let user repay the bill
    :return:
    '''
    account_data = accounts.load_current_balance(acc_data['account_id'])
    #for k,v in account_data.items():
    #    print(k,v )
    current_balance= ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' %(account_data['credit'],account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        repay_amount = input("\033[33;1mInput repay amount:\033[0m").strip()
        if len(repay_amount) >0 and repay_amount.isdigit():
            print('ddd 00')
            new_balance = transaction.make_transaction(trans_logger,account_data,'repay', repay_amount)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m''' %(new_balance['balance']))

        else:
            print('\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m' % repay_amount)

        if repay_amount == 'b':
            back_flag = True
예제 #2
0
def unfreeze_account():
    account_id = input("Please input the account id:")
    account_data = accounts.load_current_balance(account_id)
    if account_data:
        current_status = ''' --------- Account INFO --------
               Current Status : %s
               Normal : 0
               Freeze : 1''' % (account_data['status'])
        print(current_status)
        if account_data['status'] == 0:
            print("The account is Normal,no need to unfreeze!")
        else:
            user_option = input("Please confirm to unfreeze the account[y]: ")
            if user_option == 'y':
                account_data['status'] = 0
                accounts.dump_account(account_data)
                manage_log.info("account:%s   action:unfreeze_account" %
                          (account_data['id']))
                print("Account %s is Normal now!" % account_id)
            else:
                print("Nothing changed!")
    else:
        print("The account is not exists!")
예제 #3
0
def change_credit():
    account_id = input("Please input the account id:")
    account_data = accounts.load_current_balance(account_id)
    old_credit = account_data['credit']
    if account_data:
        current_balance = ''' --------- BALANCE INFO --------
               Credit :    %s
               Balance:    %s''' % (account_data['credit'], account_data['balance'])
        print(current_balance)
        account = input("\033[33;1mInput the account your want to change:\033[0m")
        if account.isdigit():
            if int(account) > -account_data["balance"]:
                account_data['credit'] = account
                accounts.dump_account(account_data)
                manage_log.info("account:%s   action:change_credit    old_credit:%s   new_credit:%s" %
                          (account_data['id'], old_credit,account_data['credit']) )
                print("\033[32;1m%s's account is changed to %s\033[0m" % (account_id,account))
            else:
                print('\033[31;1m[%s] is less than your balance,please repay your bill first!\033[0m' % account)
        else:
            print('\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m' % account)
    else:
        print("the account is not exists!")
예제 #4
0
def repay(user_data):
    account_data = accounts.load_current_balance(user_data['account_id'])
    current_balance = """
    ----------BALANCE INFOMATION----------
    Credit\t:\t%s
    Balance\t:\t%s""" % (account_data['credit'], account_data['balance'])
    print(current_balance)
    back_flag = True
    while back_flag:
        repay_amount = input("Repay amount:").strip()
        if len(repay_amount) > 0 and repay_amount.isdigit():
            print('ok')
            # 'repay' 这里可以用sys._getframe().f_code.co_name
            new_balance = transaction.make_transaction(trans_logger,
                                                       account_data, 'repay',
                                                       repay_amount)
            if new_balance:
                print('New Balance:', new_balance['balance'])

        elif repay_amount == 'b':
            back_flag = False
        else:
            print('invalid amount')
예제 #5
0
def repay(acc_data):
    account_data = accounts.load_current_balance(acc_data['account_id'])
    print(account_data)
    # for k,v in account_data.items()
    #     print(k,v)
    current_balance= ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' %(account_data['credit'],account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        repay_amount = input('\033[33;1mInput repay amount:\033[0m').strip()
        if len(repay_amount)>0 and repay_amount.isdigit():
            print("ddd 00")
            new_balance = transaction.make_transaction(trans_logger,account_data,'repay',repay_amount)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m'''%(new_balance['balance']))
        else:
            print('\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m' % repay_amount)

        if repay_amount == 'b':
            back_flag = True
    pass
예제 #6
0
def repay(acc_data):
    """
    账单还款函数
    :param acc_data:
    :return:
    """
    account_data = accounts.load_current_balance(acc_data['account_id'])
    current_balance = """-*-*-*-*-*-*-*-*- 账户余额信息 -*-*-*-*-*-*-*-*-
        Credit :    %s
        Balance:    %s\n""" % (account_data['credit'], account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        repay_amount = input("\033[32;1m 请输入还款余额\033[0m[q=quit]>>>:").strip()
        if repay_amount.isdigit():
            repay_amount = int(repay_amount)

            old_balance = account_data['balance']
            old_credit = account_data["credit"]
            if old_credit >= 30000:
                print("信用卡余额充足,不需要还款~")
                continue
            if old_balance <= repay_amount:
                print("还款金额不足,请充值后再来~")
            old_balance = account_data['balance']
            new_credit = old_credit + repay_amount
            new_balance = old_balance - repay_amount
            account_data["credit"] = new_credit
            account_data['balance'] = new_balance
            accounts.dump_account(account_data)
            print("还款成功,重新登录后生效~")
            return True
        elif repay_amount == 'q':
            back_flag = True
        else:
            print("[\033[31;1m 输入不合法,请重新输入\033[0m]")
            continue
예제 #7
0
def withdraw(user_data):
    '''
    取款功能:
    :param user_data:
    :return:
    '''
    # 获取最新账户信息
    account_data = accounts.load_current_balance(user_data['account_id'])
    # 打印账户余额信息
    current_balance = """
        ----------BALANCE INFOMATION----------
        Credit\t:\t%s
        Balance\t:\t%s""" % (account_data['credit'], account_data['balance'])
    print(current_balance)
    # 停留本层菜单标识
    back_flag = True
    while back_flag:
        # 获取取款数目
        withdraw_amount = input("Repay amount:").strip()
        # 判定用户输入有效性
        if len(withdraw_amount) > 0 and withdraw_amount.isdigit():
            print('ok')
            # 执行取款操作
            new_balance = transaction.make_transaction(trans_logger,
                                                       account_data,
                                                       'withdraw',
                                                       withdraw_amount)
            # 执行成功
            if new_balance:
                print('New Balance:', new_balance['balance'])
        # 返回上级菜单
        elif withdraw_amount == 'b':
            back_flag = False
        else:
            # 无效输入
            print('invalid amount')
예제 #8
0
def repay(acc_data):
    #取出最新的数据,为了保证数据的安全
    account_data = accounts.load_current_balance(acc_data['account_id'])
    current_balance = """
    ------balance 余额 INFO ---------
    Credit:     %s
    Balance:    %s
    """ % (account_data['id'], account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        repay_amount = input("\033[33;1m输入你要还款的金额:[放弃:q]\033[0m").strip()
        if len(repay_amount) > 0 and repay_amount.isdigit():
            new_blance = transaction.make_transaction(
                trans_logger, account_data, 'repay',
                repay_amount)  #交易完成后得到最新数据
            if new_blance:
                print("\033[33;1m最新余额:%s\033[0m" % new_blance["balance"])
        elif repay_amount == "q":
            back_flag = True
        else:
            print(
                "\033[33;1m[%s] is not a valid amount,only accept integer!!\033[0m"
                % repay_amount)
예제 #9
0
def withdraw(acc_data):
    '''
    print current balance and let user do the withdraw action
    :param acc_data:
    :return:
    '''
    account_data = accounts.load_current_balance(acc_data['account_id'])
    current_balance= ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' %(account_data['credit'],account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        withdraw_amount = input("\033[33;1mInput withdraw amount:\033[0m").strip()
        if len(withdraw_amount) >0 and withdraw_amount.isdigit():
            new_balance = transaction.make_transaction(trans_logger,account_data,'withdraw', withdraw_amount)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m''' %(new_balance['balance']))

        else:
            print('\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m' % withdraw_amount)

        if withdraw_amount == 'b':
            back_flag = True
예제 #10
0
def withdraw(acc_data):
    '''
    print current balance and let user do the withdraw action
    :param acc_data:
    :return:
    '''
    account_data = accounts.load_current_balance(acc_data['account_id'])
    current_balance= ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' %(account_data['credit'],account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        withdraw_amount = input("\033[33;1mInput withdraw amount:\033[0m").strip()
        if len(withdraw_amount) >0 and withdraw_amount.isdigit():
            new_balance = transaction.make_transaction(trans_logger,account_data,'withdraw', withdraw_amount)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m''' %(new_balance['balance']))

        else:
            print('\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m' % withdraw_amount)

        if withdraw_amount == 'b':
            back_flag = True
예제 #11
0
def account_create():   #创建账户模块

    account_id = input("create your account_id :").strip()  #用户输入要创建的用户account_id
    if len(account_id)>0 and account_id.isdigit():    #如果输入的值不为空并且是整数
        if accounts.load_current_balance(account_id):   #加载用户数据
            print("账号已存在")
            return
        for i in account_sample.acc_dic:    #   #循环初始化用户数据信息
            if i =='id':    #如果循环到id使用,用户输入的account_id
                new_data=int(account_id)
            elif i in ['credit','balance','status','pay_day']:  #如果在这里的
                new_data=account_sample.acc_dic[i]
            elif i =='enroll_date':
                #new_data=datetime.datetime.now()
                new_data=time.strftime("%Y-%m-%d")      #记录当前日期为信用卡注册时间
            elif i =='expire_date':
                struct_time = time.localtime(time.time() + 10 * 365 * 86400)
                new_data=time.strftime("%Y-%m-%d", struct_time) #记录卡失效时间为10年
            elif i =='password':
                new_data=input("enter your password:")   #用户输入password
            account_sample.acc_dic[i]=new_data  #每次循环完成为account_dic赋新值
        print(account_sample.acc_dic)
        accounts.dump_account(account_sample.acc_dic)   #将用户文件存储到本地
    else:return
예제 #12
0
def repay(acc_data):
    '''
    打印当前余额,让用户偿还账单
    :param acc_data:
    :return:
    '''
    accout_data = accounts.load_current_balance(acc_data['account_id'])
    current_balance = '''----------BALANCE INFO--------
        Credit : %s
        Balabce: %s'''%(account_data['credit'],accout_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        repay_amount = input("\033[33;1mInput repay amount:\033[0m").strip()
        if len(repay_amount)>0 and repay_amount.isdigit():
#            print('ddd 00')
            new_balance = transaction.make_transaction(trans_logger,accout_data,'repay',repay_amount)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m''' %(new_balance['balance']))
            else:
                print('\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m' % withdraw_amount)

            if withdraw_amount == 'b':
                back_flag = True
예제 #13
0
파일: main.py 프로젝트: LosMoros/atm
def repay(acc_data):
    '''
    print current balance and let user repay the bill
    :return:
    '''
    account_data = accounts.load_current_balance(acc_data['account_id'])
    # 再从硬盘加载一次数据, 为了确保数据是最新的
    # for k,v in account_data.items():
    #    print(k,v )
    current_balance = ''' --------- BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' % (account_data['credit'], account_data['balance'])
    print(current_balance)
    repay_amount = input("\033[33;1mInput repay amount:\033[0m").strip()
    if len(repay_amount) > 0 and repay_amount.isdigit():
        new_balance = transaction.make_transaction(trans_logger, account_data,
                                                   'repay', repay_amount)
        if new_balance:
            print('''\033[42;1mNew Balance:%s\033[0m''' %
                  (new_balance['balance']))
    else:
        print(
            '\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m'
            % repay_amount)
예제 #14
0
파일: main.py 프로젝트: cuitianfeng/Python
def transfer(acc_data):
    '''

    :param acc_data:
    :return:
    '''
    account_data = accounts.load_current_balance(acc_data['account_id'])
    current_balance = ''' --------- BALANCE INFO --------
            Credit :    %s
            Balance:    %s''' % (account_data['credit'],
                                 account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        t_acc = input(
            "\033[33;1mInput transfer account<输入转账户'1234 or 4321'>:\033[0m"
        ).strip()
        transfer_amount = input(
            "\033[33;1mInput transfer amount<输入转数量>:\033[0m").strip()
        if len(transfer_amount) > 0 and transfer_amount.isdigit():
            # print('ddd 00')
            new_balance = transaction.make_transaction(trans_logger,
                                                       account_data,
                                                       'transfer',
                                                       transfer_amount, t_acc)
            if new_balance:
                print('''\033[42;1mNew Balance:%s\033[0m''' %
                      (new_balance['balance']))

        else:
            print(
                '\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m'
                % transfer_amount)

        if transfer_amount == 'b':
            back_flag = True
예제 #15
0
def borrow(user_date):
    '''
    普通用户:借现
    :param user_date:
    :return:
    '''
    account_date = accounts.load_current_balance(user_date['user_id'])
    current_balance = ''' --------- 账户余额信息 --------
信用额度 :%s
剩余额度:%s''' % (account_date['credit'], account_date['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:
        withdraw_mount = input('请输入借款金额: ').strip()
        if withdraw_mount.isdigit() and len(withdraw_mount):
            new_balance = transaction.make_transaction(account_date,
                                                       'withdraw',
                                                       withdraw_mount)
            if new_balance:
                print('账户新余额为%s' % (new_balance['balance']))

        if withdraw_mount == 'b':
            back_flag = True
            continue
예제 #16
0
def withdraw(acc_data):
    account_data = accounts.load_current_balance(acc_data['account_id'])
    print('Balance Info'.center(50, '-'))
    print(u'''
        余额:   %d
        ''' % account_data['balance'])
    back_flag = True
    while back_flag:
        withdraw_amount = input(
            '\33[33;1mInput Withdraw Amount: \33[0m').strip()
        if len(withdraw_amount) == 0: continue
        if withdraw_amount.isdigit():
            new_balance = transaction.make_transaction(trans_logger,
                                                       account_data,
                                                       'withdraw',
                                                       withdraw_amount)
            if new_balance:
                print('\33[42;1mNew Balance is %s : \33[0m' %
                      new_balance['balance'])
            back_flag = False
        else:
            print(
                '\33[31;1m%s is not a valid amount,only accept integer : \33[0m'
                % withdraw_amount)
예제 #17
0
def transfer(acc_data):
    '''
    转账

    输入参数:
        acc_data,用户的user_data,即内存中的用户当前的状态信息以及数据库信息。
    创建变量:
        account_data,用户账户的json数据库信息。
        current_balance,用于余额提示语。
        transfer_amount,转账金额。
        transfer_account,收款人的账户。
        transfer_account_data,收款人的json数据库内容。
        new_account_data,当前用户执行完交易后返回的json数据库内容。
        new_transfer_account_data,收款人行完交易后返回的json数据库内容。

    执行过程:
         提示用户输入收款人的id,调用accounts.load_current_balance,检查该id的json文件是否存在。
         如果不存在,就提示出错。
        提示用户输入转账金额。调用transaction.make_transaction函数,把当前用户的账户余额减去转账金额。
        如果交易成功,就再次调用make_transaction函数,把转账金额转入收款人的账户。
        当以上2步都执行成功,才会完成整个转账操作。
        make_transaction函数传入以下几个参数:
            account_data,交易的用户json文件信息。
            'transfer',交易类型
            transfer_amount,转账金额。
        make_transaction函数进行处理,可能返回以下值
            如果交易失败,返回 None,
            如果交易成功,返回account_data,此处的account_data为交易后的用户的json库内容。

    返回值:
        返回交易成功后的当前用户的json数据信息,以及收款人的json数据信息。
    '''
    account_data = accounts.load_current_balance(acc_data['account_id'])
    current_balance= ''' ---------ID:%s BALANCE INFO --------
        Credit :    %s
        Balance:    %s''' %(account_data['id'],account_data['credit'],account_data['balance'])
    print(current_balance)
    back_flag = False
    while not back_flag:

        transfer_account = input("\033[33;1mInput Which Account ID transfer to:\033[0m").strip()
        if len(transfer_account) > 0 and transfer_account.isalnum():
            transfer_account_data = accounts.load_current_balance(transfer_account)
            if transfer_account_data==None:
                print("\033[31;1m ID:[{}] doesn't exists !\033[0m".format(transfer_account))
                continue
            elif transfer_account_data:
                print("You are going to transfer to USER:【{}】!".format(transfer_account))
        else:
            print('\033[31;1m[{}] is not a valid Account ID!\033[0m'.format(transfer_account))
            continue
        print("Press 'b' back to Main menu.")
        transfer_amount=input("\033[33;1mInput transfer amount:\033[0m").strip()
        if transfer_amount == 'b':
            back_flag = True
            print("Back to menu.")
        elif len(transfer_amount) > 0 and transfer_amount.isdigit():
            new_account_data = transaction.make_transaction( \
            account_data, 'transfer', transfer_amount)
            if new_account_data:
                new_transfer_account_data = transaction.make_transaction( \
                    transfer_account_data, 'repay', transfer_amount)
                if new_transfer_account_data:
                    print("Amount [{}] has been transfer to ID:[{}]".format(transfer_amount,new_transfer_account_data['id']))
                    print('''\033[42;1mID:【{}】,Your New Balance:{}\033[0m''' .format (new_account_data['id'],new_account_data['balance']))

        else:
            print('\033[31;1m[%s] is not a valid amount, only accept integer!\033[0m' % transfer_amount)
예제 #18
0
# from conf import settings
import os
import sys
# from core import main
# BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# sys.path.append(BASE_DIR)
# from bin import atm
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
from core import accounts

# 测试读取账户信息功能
acc = accounts.load_current_balance('1234')
print(acc)
# type_obj=settings.LOG_TYPES
# 测试日志功能
# log=logger.logger("transaction")
# log.info("测试日志内容")
예제 #19
0
파일: main.py 프로젝트: LosMoros/atm
def account_info(acc_data):
    # print(user_data)
    account_data = accounts.load_current_balance(acc_data['account_id'])
    print(account_data)
예제 #20
0
def account_info(acc_data):
    # 查看账号信息
    account_data = accounts.load_current_balance(acc_data['account_id'])
    print(account_data)
예제 #21
0
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
'''
Administrator 
2018/8/14 
'''
import os,sys,logging,time
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from core import accounts
from core import logger
shopping_log=logger.logger("shopping")

product_list=accounts.load_current_balance()
#print(product_list)


def shopping_action(sum_amount):
        # saving=input("please input your saving:")
        saving=sum_amount
        shopping_car=[]
        if saving.isdigit():
                saving=float(saving)
                while True:
                        for j in product_list.items():
                                print(j)
                        choice=input('choice your product number[quit:q]')
                        if choice.isdigit():
                                if choice in product_list:
                                        p_item=product_list[choice]
                                        for name,price in p_item.items():
                                                continue