简单的订单系统,使用的os目录

 一:主要是是os模板练习案例。

import os
import datetime
import time

DB_PATH = 'db'


def history(user_path):
    if not os.path.exists(user_path):
        print('无历史记录')
        return

    with open(user_path, mode='r', encoding='utf-8') as f:
        for line in f:
            line = line.strip()
            print(line)


def booking(user_path):
    while True:
        location = input('请输入景区,或者输入q/Q,退出订票:')
        if location.upper().strip() == "Q":
            break

        book_num = input('输入订几张:')
        ctime_string = datetime.datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
        book_string = '{},{},{}\n'.format(location, book_num, ctime_string)

        with open(user_path, mode='a', encoding='utf-8') as f:
            f.write(book_string)



def run():
    if not os.path.exists(DB_PATH):
        os.makedirs(DB_PATH)

    # 2.
    user_name = input('请输入用户名:')
    user_path = os.path.join(DB_PATH, '{}.txt'.format(user_name))
    if os.path.exists(user_path):
        print('{}用户已经存在'.format(user_name))
    else:
        print('{}用户是新用户'.format(user_name))

    # 3.
    func_dict = {'1': history, '2': booking}
    while True:
        print('1:是查看历史订单,2:预定')
        choice = input('请选择功能,或者退出q/Q:')
        if choice.upper().strip() == 'Q':
            return

        func = func_dict.get(choice.strip())

        if not func:
            print('序号输入错误')
            continue

        func(user_path)


run()

 二:账号注册

import os
import sys
import hashlib
import json
import datetime

DATA_FILE = "user_info.txt"
SALT_STR = "dgd5"


def md5(*args):
    salt_str, user_pwd = args
    hashlib_md5 = hashlib.md5(salt_str.encode('utf-8'))
    hashlib_md5.update(user_pwd.encode('utf-8'))
    pwd_str = hashlib_md5.hexdigest()
    return pwd_str


def run():
    while True:
        flag = 0
        user_name = input('请输入注册的用户:')

        if os.path.isfile(DATA_FILE):
            with open(DATA_FILE, mode='r', encoding='utf-8') as file:
                for line in file:
                    if user_name in line:
                        print('这个{}用户已经被注册,请重新注册其它账号'.format(user_name))
                        flag = 1
                        break
        if flag:
            continue

        user_pwd = input('请输入用户的密码:')
        user_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        pwd_str = md5(SALT_STR, user_pwd)

        with open(DATA_FILE, mode='a', encoding='utf-8') as file:
            mesg = "{},{},{}".format(user_name.strip(), pwd_str.strip(), user_time.strip())
            file.write(mesg)
            file.write('\n')


run()

三:时间有限,后面会补充os目录其它功能

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值