py-e-mail工具
2025-02-10 10:25:12
发布于:北京
py-e-mail工具
import time
def slow_print(*obj, end='\n', delay=0.07):
    for i in obj:
        for j in str(i):
            print(j, end='', flush=True)
            time.sleep(delay)
    print(end, end='')
def base37_to_int(s):
    """Convert a base 37 string to an integer."""
    chars = '0123456789abcdefghijklmnopqrstuvwxyz '
    n = 0
    for char in s:
        n = n * 37 + chars.index(char)
    return n
def int_to_base37(n):
    """Convert an integer to its base 37 representation."""
    if n == 0:
        return '0'
    chars = '0123456789abcdefghijklmnopqrstuvwxyz '
    base37 = ''
    while n:
        base37 = chars[n % 37] + base37
        n //= 37
    return base37
slow_print("你好,这是py-e-mail邮件工具,欢迎使用!")
slow_print("请你选择你现在要执行的命令:\n0.清除所有数据\n1.注册\n2.登录\n3.退出\n请输入你的选择:",end='')
now_username = ""
while True:
    type = int(input())
    if type == 0:
        slow_print("你确定要恢复到初始状态吗?(y/n):",end='')
        if input() == "y":
            with open("users.txt","w+") as f:
                slow_print("正在清",delay=0.5,end='')
            with open("message.txt","w+") as f:
                slow_print("除...",delay=0.5)
            slow_print("已恢复到初始状态!")
        else:
            slow_print("已取消!")
    elif type == 1:
        with open("users.txt","a") as f:
            slow_print("请输入你想要注册的用户名:",end='')
            username = input()
            slow_print("请输入你的密码(只能包含数字):",end='')
            try:
                password = int(input())
                if f.tell() > 0:
                    f.write("\n" + username + " " + hex(password)[2:])
                else:
                    f.write(username + " " + hex(password)[2:])
            except ValueError:
                slow_print("密码只能包含数字!")
            else:
                slow_print("注册成功!")
        
    elif type == 2:
        slow_print("请输入你的名字:",end='')
        username = input()
        slow_print("请输入你的密码:",end='')
        password = int(input())
        with open("users.txt","r") as f:
            for line in f:
                if line == "\n":
                    continue
                true_username = line.split()[0]
                true_password = int(line.split()[1],16)
                if true_username == username and true_password == password:
                    slow_print("登录成功!")
                    now_username = username
                    break
            else:
                slow_print("登录失败!")
    elif type == 3:
        exit()
    else:
        slow_print("输入错误!")
        if now_username == "":
            slow_print("请你选择你现在要执行的命令:\n1.注册\n2.登录\n3.退出\n请输入你的选择:",end='')
        else:
            break
    if now_username == "":
        slow_print("请你选择你现在要执行的命令:\n1.注册\n2.登录\n3.退出\n请输入你的选择:",end='')
    else:
        break
while True:
        slow_print("请你选择你现在要执行的命令:\n1.发送消息\n2.查看消息\n3.退出\n4.登出\n请输入你的选择:",end='')
        type = int(input())
        if type == 1:
            slow_print("请输入你要发送的消息(只能包含小写英文字母或空格):",end='')
            message = input()
            with open("main-e-mail.txt","a") as f:
                f.write(time.strftime("%Y/%m/%d_%H:%M:%S") + " " + now_username + " " + str(base37_to_int(message)) + "\n")
        elif type == 2:
            with open("main-e-mail.txt","r") as f:
                for line in f:
                    parts = line.split(" ")
                    if len(parts) >= 3:
                        timestamp, username, message_code = parts[0], parts[1], parts[2]
                        message = int_to_base37(int(message_code))
                        slow_print("用户“", username, "”在", timestamp, "的时候发送了“", message, "”", end='\n')
        elif type == 3:
            exit()
        elif type == 4:
            now_username = ""
            slow_print("登出成功!")
            slow_print("请你选择你现在要执行的命令:\n1.注册\n2.登录\n3.退出\n请输入你的选择:",end='')
            while True:
                type = int(input())
                if type == 1:
                    with open("users.txt","a") as f:
                        slow_print("请输入你想要注册的用户名:",end='')
                        username = input()
                        slow_print("请输入你的密码(只能包含数字):",end='')
                        try:
                            password = int(input())
                            print(str(f))
                            if len(str(f)) > 1:
                                f.write("\n" + username + " " + hex(password)[2:])
                            else:
                                f.write(username + " " + hex(password)[2:])
                        except ValueError:
                            slow_print("密码只能包含数字!")
                        else:
                            slow_print("注册成功!")
                    
                elif type == 2:
                    slow_print("请输入你的名字:",end='')
                    username = input()
                    slow_print("请输入你的密码:",end='')
                    password = int(input())
                    with open("users.txt","r") as f:
                        for line in f:
                            if line == "\n":
                                continue
                            true_username = line.split()[0]
                            true_password = int(line.split()[1],16)
                            if true_username == username and true_password == password:
                                slow_print("登录成功!")
                                now_username = username
                                break
                        else:
                            slow_print("登录失败!")
                elif type == 3:
                    exit()
                else:
                    slow_print("输入错误!")
                if now_username == "":
                    slow_print("请你选择你现在要执行的命令:\n1.注册\n2.登录\n3.退出\n请输入你的选择:",end='')
                else:
                    break
            continue
        else:
            slow_print("输入错误!")
            slow_print("请你选择你现在要执行的命令:\n1.发送消息\n2.查看消息\n3.退出\n4.登出\n请输入你的选择:",end='')
这里空空如也










有帮助,赞一个