zoukankan      html  css  js  c++  java
  • 模拟博客园登陆(部分简单操作未加上)

    import os
    state=0
    name=""
    def wrapper(f):
    def inner(*args,**kwargs):
    if state==1:
    ret=f(*args,**kwargs)
    wel=ret[:3]+name+ret[3:]
    print(wel)
    return ret
    else:
    if login():
    ret = f(*args, **kwargs)
    wel = ret[:3] + name + ret[3:]
    print(wel)
    return ret
    elif register():
    ret = f(*args, **kwargs)
    wel = ret[:3] + name + ret[3:]
    print(wel)
    return ret
    return inner
    def goto(s):
    if s==1:
    login()
    elif s==2:
    register()
    elif s==3:
    article()
    elif s==4:
    comment()
    elif s==5:
    diary()
    elif s==6:
    collect()
    elif s == 7:
    logout()
    elif s == 8:
    leave()
    def users():
    dic={}
    with open(os.path.dirname(__file__) + '/userinfo',encoding="utf-8",mode="r+") as f:
    for i in f:
    dic[i.strip().split("|")[0]]= i.strip().split("|")[1]
    return dic
    def login():
    count=0
    while count<3:
    global name
    name=input("请输入用户名").strip()
    password=input("请输入密码").strip()
    dic=users()
    if name in dic and password==dic[name]:
    global state
    state = 1
    print("登陆成功")
    count=3
    return 1
    else:
    print("登陆失败")
    count+=1
    return 0
    def register():
    global name
    name = input("请输入用户名").strip()
    password = input("请输入密码").strip()
    with open(os.path.dirname(__file__) + '/userinfo',encoding="utf-8",mode="a+") as f:
    dic = users()
    if name in dic:
    print("用户名已存在")
    else:
    f.write(f" {name}|{password}")
    global state
    state=1
    print("注册成功")
    return 1
    @wrapper
    def article():
    print("直接写还是导入文件")
    choice = input().strip()
    if choice == "1":
    content = input().strip()
    with open(os.path.dirname(__file__) + '/create', encoding="utf-8", mode="a+") as f:
    f.write(content)
    elif choice == "2":
    content = input().strip()
    with open(content, encoding="utf-8", mode="r") as f1:
    with open(os.path.dirname(__file__) + '/ uploading', encoding="utf-8", mode="a+") as f:
    for i in f1:
    f.write(i)
    return "欢迎来到文章"
    @wrapper
    def comment():
    print(os.listdir(os.path.dirname(__file__) + "/article"))
    choice=input("请选择要评论的文章")
    comments=input("请输入你的评论")
    with open(os.path.dirname(__file__) +"/article/"+choice, encoding="utf-8", mode="a+") as f:
    f.write(f"{name} ")
    f.write(f"{comments} ")
    return "欢迎来到评论"
    @wrapper
    def diary():
    return "欢迎来到日记"
    @wrapper
    def collect():
    return "欢迎来到收藏"
    @wrapper
    def logout():
    print("登出")
    def leave():
    print("离开当前操作")
    print(
    '''
    1.请登录
    2.请注册
    3.进入文章界面
    4.进入评论界面
    5.进入日记界面
    6.进入收藏界面
    7.注销账户
    8.退出整个程序
    '''
    )
    a=int(input("请输入你要选择的操作").strip())
    goto(a)
  • 相关阅读:
    一个十分诡异的NullReferenceException异常!
    如何去掉TabControl控件默认添加的TabPage
    GDI+发生一般性错误的解决方法
    C#中各种数组的性能比较
    酷享娱乐新生活
    关于ImageList.Images集合的特殊行为!
    WinForm窗体之间交互的一些方法
    实现单实例应用程序的三种方案
    MySql_Close 释放资源
    数组之List
  • 原文地址:https://www.cnblogs.com/diracy/p/13125171.html
Copyright © 2011-2022 走看看