控制台版文章管理系统:
1、用户管理系统
2、文章的管理和控制
import json
import sys
import os
import time
import hashlib
def write(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_new):
with open(article_new, "r") as fle:
w = fle.readlines()
for word in w:
print(word)
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 enroll():
enroll_ls = dict()
name = input('请输入注册的用户名:')
password = int(input('请输入密码:'))
if input('是否注册') == 'yes' or input('是否注册') == 'Yes':
change = input('是否加密')
if change == 'yes' or change == 'Yes':
password = md5(password)
enroll_ls[name] = password
print('注册成功!')
return enroll_ls
else:
print('注册失败!')
return enroll_ls
def md5(password):
password = str(password)
password1 = hashlib.md5()
password1.update(password.encode("utf8"))
password = password1.hexdigest()
return password
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_new)
option1 = input('是否继续')
if option1 == 'yes' or 'Yes':
write(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\\python3\\a.txt", 'r')
login_ls = json.load(ls)
print(login_ls)
ls.close()
if login(login_ls):
get_ls()
elif option1 == 2:
enroll_dict = enroll()
json.dump(enroll_dict, open("D:\\python\\IO\\ls.txt", 'w'))
elif option1 == 3:
sys.exit()
————————————————
版权声明:本文为CSDN博主「m0_64365851」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_64365851/article/details/124676572