python控制台

import json
import sys
import os
import time
import hashlib


def login (login_ls):
    """登录过程"""
    name = input('请输入用户名:')
    if name in login_ls:
        password = int(input('请输入密码:'))
        if password == int(login_ls[name]):
            print('登录成功!')
            return True
        else:
            print('密码错误!')
            return False
    else:
        print('该用户不存在!')
        return False


def get_md5 (password):
    """密码加密"""
    password = str(password)
    password1 = hashlib.md5()
    password1.update(password.encode("utf8"))
    password = password1.hexdigest()
    return password


def enroll ():
    """注册过程"""
    enroll_ls = dict()
    name = input('请输入注册的用户名:')
    password = int(input('请输入密码:'))
    if input('是否注册') == 'yes' or input('是否注册') == 'Yes':
        # password = hashlib.md5().update(password)
        change = input('是否加密')
        if change == 'yes' or change == 'Yes':
            password = get_md5(password)
        enroll_ls[name] = password
        print('注册成功!')
        return enroll_ls
    else:
        print('注册失败!')
        return enroll_ls


def write_article (article_new):
    """继续写文章"""
    while True:
        with open(article_new, "a") as fle:
            w = fle.write(input('请输入:')+'\n')
            fle.flush()
        if w == 0:
            break


def read_article (article_new):
    """读取文章"""
    with open(article_new, "r") as fle:
        w = fle.readlines()
        for word in w:
            print(word)

def get_ls ():
    article = os.listdir("D:\\python\\IO\\ls")  # 获取文章目录
    print('文章目录')

    for i in range(0,len(article)):
        print(f'{i+1}.{article[i]}')

    option = int(input('输入要查找的文件的数字:'))
    article_new = os.path.join("D:\\python\\IO\\ls", article[option-1])
    now_time = time.strftime("%Y-%m-%d %H:%M:%S")  # 获取当前时间
    old_time = time.ctime(os.path.getctime(article_new))  # 获取文件的创建时间
    change_time = time.ctime(os.path.getmtime(article_new))  # 获取上一次修改时间
    article_dig = os.path.getsize(article_new)  # 获取文件大小
    print(f'文件:{article[option]}\n文件大小{article_dig}\n当前时间{now_time}')
    print(f'文件创建时间{old_time}\n文件修改时间{change_time}')
    read_article(article_new)
    option1 = input('是否继续')

    if option1 == 'yes' or 'Yes':
        write_article(article_new)


if __name__ == "__main__":
    print(' ' * 10 + '登录界面')
    print('~ * ' * 10)
    print(' ' * 12 + '1. 用户登录\n' + ' ' * 12 + '2. 新用户注册\n' + ' ' * 12 + '3. 退出系统')
    print('~ * ' * 10)
    option1 = int(input('(温馨提示)请输入您的选项:'))
    if option1 == 1:
        ls = open("D:\\python\\IO\\ls.txt", 'r')
        login_ls = json.load(ls)
        print(login_ls)
        ls.close()

        if login(login_ls):
            get_ls()


    elif option1 == 2:
        '''
        ls = open("D:\\python\\IO\\ls.txt", 'a')
        enroll_ls = json.load(ls)
        print(enroll_ls)
        '''
        enroll_dict = enroll()
        # ls = open("D:\\python.1.txt", 'w')
        # enroll_dict = enroll(enroll_ls)
        # ls.write(enroll_dict)
        json.dump(enroll_dict, open("D:\\python\\IO\\ls.txt", 'w'))
        # ls.close()


    elif option1 == 3:

        sys.exit()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值