コード例 #1
0
def bank():
    shop_run.judge()
    shutil.copy('user.conf', 'user.conf.back')
    with open('user.conf', 'r') as f:
        u_count = 1
        for line in f:
            if u_count == 1:
                salary = int(line.split('|')[2])
                u_count += 1
    input_money = raw_input('您的账户余额为{}元,请输入要充值的金额(q=quit):'.format(salary))
    if input_money == 'q':
        return
    elif input_money.isdigit():
        print('正在充值,请稍后。。。')
        time.sleep(2)
        new_salary = salary + int(input_money)
        u_count = 1
        with open('user.conf.back', 'r') as f1, open('user.conf', 'w') as f2:
            for line in f1:
                if u_count == 1:
                    f2.write('|'.join([
                        line.split('|')[0],
                        line.split('|')[1],
                        str(new_salary)
                    ]))
                    f2.write('\n')
                    u_count += 1
                else:
                    f2.write(line)
    print('您充值后的金额为{}元'.format(new_salary))
コード例 #2
0
ファイル: cost.py プロジェクト: yinsendemogui/Git
def price():
    s_count = 1
    shop_run.judge()
    if os.path.exists('shop_goods.conf'):
        f = open('user.conf', 'r')
        count = 1
        for line in f:
            if s_count == 1:
                aa = line.strip().split('|')
                salary = int(aa[2])
            elif line.strip() == '[购物车商品]':
                start_count = count
            elif line.strip() == '[历史信息]':
                end_count = count
            s_count += 1
            count += 1
        f.close()
        with open('user.conf', 'r') as f1:
            user_salary = 0
            shop_count = 0
            for line in f1:
                shop_count += 1
                if start_count < shop_count < end_count:
                    with open('shop_goods.conf', 'r') as f2:
                        for lines in f2:
                            if line.strip() == lines.split(',')[1].strip():
                                user_salary += int(lines.strip().split(',')[2])
        if salary >= user_salary:
            return (True, salary, user_salary)
        else:
            return (False, salary, user_salary)
    else:
        return
コード例 #3
0
ファイル: accounts.py プロジェクト: yinsendemogui/Git
def settle():
    d_count = 1
    shop_run.judge()
    if os.path.exists('shop_goods.conf'):
        ft,salary,user_salary = cost.price()
        if ft:
            print ('您的资金充足,正在进行结算,请稍后。。。')
            time.sleep(3)
            shutil.copy('user.conf','user.conf.back')
            residue_salary = salary - user_salary
            with open('user.conf','r') as f:
                line_count = 0
                for line in f:
                    line_count += 1
                    if line.strip() == '[购物车商品]':
                        start_count = line_count
                    elif line.strip() == '[历史信息]':
                        end_count = line_count
            with open('user.conf.back','r') as f1, open('user.conf','w') as f2:
                user_count = 0
                for line in f1:
                    user_count += 1
                    if line.count('\n') == len(line):
                        f2.write(line)
                    elif user_count == 1:
                        f2.write('|'.join([line.strip().split('|')[0],line.strip().split('|')[1],str(residue_salary)])+'\n')
                    elif start_count < user_count < end_count - 1:
                        BUY_GOOD[d_count] = [line.strip(),time.asctime()]
                        d_count += 1
                    else:
                        f2.write(line)
            shutil.copy('user.conf','user.conf.back')
            with open('user.conf.back','r') as f1, open('user.conf','w') as f2:
                for line in f1:
                    f2.write(line)
                for key in BUY_GOOD:
                    f2.write(','.join([BUY_GOOD[key][0],BUY_GOOD[key][1]])+'\n')
            print ('您的消费金额为{}元,账户余额为{}元'.format(user_salary,residue_salary))
            exit()
        else:
            print '您的账户余额不足,,请充值后再进行结账。。。'
            time.sleep(2)
    else:
        print ('没有购买任何物品,。。')
コード例 #4
0
def trade():
    shop_run.judge()
    if not os.path.exists('shop_goods.conf'):
        f = open('shop_goods.conf','w')
        for i in xrange(1,9):
            row = str(i)
            f.write(','.join([row,GOOD_DICT[row][0],str(GOOD_DICT[row][1])])+'\n')
        f.close()
    f = open('shop_goods.conf', 'r')
    for line in f:
        print line.strip()
    f.close()
    shop_run.code()
    while TAG:
        good_choice = raw_input('请输入您选择购买的商品(可同时多项选择):')
        if set(good_choice) <= set('12345678'):
            shop_run.judge()
            f = open('user.conf','r')
            lines_count = 0
            for line in f:
                lines_count += 1
                if line.strip() == SIGN_2:
                    end_count = lines_count
            f.close()
            shutil.copy('user.conf','user.conf.back')
            with open('user.conf.back','r') as f1, open('user.conf','w') as f2:
                end_line = end_count - 1
                cart_count = 1
                for line in f1:
                    if cart_count == end_line - 1:
                        f = open('shop_goods.conf','r')
                        for lines in f:
                            for goods in good_choice:
                                if lines.split(',')[0] == goods:
                                    f2.write(lines.split(',')[1].strip()+'\n')
                        f2.write('\n')
                    else:
                        f2.write(line)
                    cart_count += 1
            shop_run.code()
            return
        else:
            print ('无此商品,请重试')
コード例 #5
0
ファイル: history.py プロジェクト: yinsendemogui/Git
def past():
    shop_run.judge()
    shutil.copy('user.conf', 'user.conf.back')
    f = open('user.conf', 'r')
    count_1 = 0
    for line in f:
        count_1 += 1
        if line.strip() == '[历史信息]':
            start_count = count_1
    f.close()
    print('您以往购买的商品有:')
    with open('user.conf', 'r') as f1:
        COUNT = 1
        count_2 = 0
        for line in f1:
            count_2 += 1
            if count_2 > start_count:
                print('{},商品:{}\t购买日期:{}'.format(COUNT,
                                                 line.split(',')[0],
                                                 line.split(',')[1]))
                time.sleep(0.5)
                COUNT += 1
    print('您共购买{}件商品'.format(COUNT - 1))
    shop_run.code()
コード例 #6
0
ファイル: shop_car.py プロジェクト: yinsendemogui/Git
def cart():
    while TAG:
        COUNT = 0
        shop_run.judge()
        count = 1
        shutil.copy('user.conf', 'user.conf.back')
        f = open('user.conf', 'r')
        for line in f:
            if line.strip() == '[购物车商品]':
                star_count = count
            elif line.strip() == '[历史信息]':
                end_count = count
            count += 1
        f.close()
        print('已加入购物车的商品有:')
        with open('user.conf.back', 'r') as f1:
            shop_count = 0
            for line in f1:
                shop_count += 1
                if shop_count == 4 and line.count('\n') == len(line):
                    print('没有选择任何商品。。。')
                    return
                elif star_count < shop_count < end_count:
                    if line.count('\n') == len(line):
                        continue
                    else:
                        COUNT += 1
                        print COUNT, '---', line.strip()
                        DICT_GOOD[str(COUNT)] = line.strip()
                else:
                    continue
        cart_choice = raw_input(
            '请选择购物车的操作功能(c=clear/d=delete/p=pass):'.strip().lower())
        if cart_choice == 'd':
            while TAG:
                del_choice = raw_input('请输入您要删除的商品序号(单项选择删除):')
                if del_choice.isdigit() and 0 < int(del_choice) <= COUNT:
                    shutil.copy('user.conf', 'user.conf.back')
                    with open('user.conf', 'r') as f:
                        count = 1
                        for line in f:
                            if line.strip() == '[购物车商品]':
                                star_count = count
                            elif line.strip() == '[历史信息]':
                                end_count = count
                            count += 1
                        with open('user.conf.back',
                                  'r') as f1, open('user.conf', 'w') as f2:
                            shop_count = 0
                            yn = 0
                            for line in f1:
                                shop_count += 1
                                if line.count('\n') == len(line):
                                    f2.write(line)
                                elif star_count < shop_count < end_count:
                                    if line.strip(
                                    ) == DICT_GOOD[del_choice] and yn == 0:
                                        yn += 1
                                        continue
                                    else:
                                        f2.write(line)
                                else:
                                    f2.write(line)
                            break
                else:
                    print('您输入的有误,请重新输入')
        elif cart_choice == 'p':
            return
        elif cart_choice == 'c':
            shutil.copy('user.conf', 'user.conf.back')
            f = open('user.conf', 'r')
            count = 1
            for line in f:
                if line.strip() == '[购物车商品]':
                    star_count = count
                elif line.strip() == '[历史信息]':
                    end_count = count
                count += 1
            f.close()
            print('已加入购物车的商品有:')
            with open('user.conf.back', 'r') as f1, open('user.conf',
                                                         'w') as f2:
                shop_count = 0
                for line in f1:
                    shop_count += 1
                    if line.count('\n') == len(line):
                        f2.write(line)
                    elif star_count < shop_count < end_count:
                        continue
                    else:
                        f2.write(line)
            print('购物车已经清空')
            return
        else:
            print('您输入的有误,请重试')
    shop_run.code()