python 用户持久化

重新书写(函数知识)博客系统

题目要求

所有的用户:[{“name”:xx, "password":mima, "age"xxx}, {}, {}, {}]
    所有文章:[{"title": "23", "content": "", "publish_time": datetime.now(), "modify_time": datetime.now(), "author": }]
    while True:
        1、用户注册
        2、用户登录
        3、退出系统

            登录成功
            1、发表文章
            2、修改自己发表的文章
            3、查看自己发表的文章
            4、查看所有文章
                
                1、
                请输入文章标题
                    于妙泽23式
                请输入文章内容:
                    xxxx
                    
                    保持文章
                    

import sys
from datetime import datetime



users = []
login_user = {}
articles = []


def init():
	pass


def main():


	print("------------------欢迎进入博客系统------------------\n")
	print("\t\t1、用户注册\n")
	print("\t\t2、用户登录\n")
	print("\t\t3、退出系统\n")
	print("------------------------------------------------------\n")
	return input("请输入您的操作:")


def main_blog():

	print("------------------欢迎进入博客系统------------------\n")
	print("\t\t1、发布博客\n")
	print("\t\t2、查看自己博客\n")
	print("\t\t3、删除自己博客\n")
	print("\t\t4、回到上一级\n")
	print("------------------------------------------------------\n")
	return input("请输入您的操作:")


def is_exists(username):
	for i in users:
		if i.get("username") == username:
			return True
	return False


def check_reg(username, password, comfirm_pass):

	if username is None or username.strip() == "":
		print("用户名不能为空")
		return False
	if is_exists(username):
		print("该用户名称已经存在,请重新注册")
		return False

	if password == None or password.strip() == "" or len(password) < 3:
		print("对不起,密码不能为空或者长度不能小于3位")
		return False

	if password.strip() != comfirm_pass.strip():
		print("对不起,两次密码不一致")
		return False
	return True

while True:
	choice = main()
	if choice == "1":
		while True:
			username = input("请输入用户名:")
			password = input("请输入密码:")
			comfirm_pass = input("请再次输入密码:")
			break

	elif choice == "2":
		username = input("请输入用户名:")
		password = input("请输入密码:")


		while True:
			choice = main_blog()
			if choice == "1":
				title = input("请输入博客标题:")
				content = input("请输入博客内容:")
				article = {}
				article["title"] = title
				article['content'] = content
				article["publish_time"] = datetime.now()
				article["modify_time"] = datetime.now()
				article["author"] = login_user.get("username")
				articles.append(article)
				print("当前所有文章是:")
				print(articles)
			elif choice == "2":
				print("查看自己博客")
				print(articles)
			elif choice == "3":
				print("删除博客")
			else:
				break

		else:
			print("登录失败,用户名或者密码错误,请重新登录")
	else:
		yes = input("您确定要退出系统?(yes):")
		if yes.lower() == "yes":
			sys.exit()

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值