美文网首页
python_密码本.py

python_密码本.py

作者: DOVE_5214 | 来源:发表于2017-12-03 10:52 被阅读0次
"""
    -*- conding:UTF-8 -*-

    / 我一直在找你
    / 我找到你时
    / 我就等于找到了全世界

          DOVE


"""
import os
import os.path
infors = {}  # 创建一个储存内容的字典


url_file = open("D:\python\password.txt", "r+")  # 打开文件
content = url_file.readlines()  # 缓冲文件内容到content


url_file.close()
def menu():
    """创建一个菜单函数"""
    print("=" * 30)
    name = "密码本 V1.0"
    print(name.center(30))
    print("增加 【1】")
    print("删除 【2】")
    print("修改 【3】")
    print("查找 【4】")
    print("退出 【5】")
    print("=" * 30)


def add():
    """创建一个添加信息函数"""

    url_file = open("D:\python\password.txt", "r+")
    input_add_name = input("请输入要添加的名称:")
    add_call_find = find(input_add_name)
    if add_call_find[0] == 0:

        input_add_url= input("请输入你要添加的URL:")
        input_add_explian = input("请输入URL的说明:")
        infors["URL名称:"] = input_add_name
        infors["URL:"] = input_add_url
        infors["URL说明:"] = input_add_explian


        data = str(infors) + "\n"
        url_file.seek(0,2)
        url_file.write(data)
        url_file.flush()

        url_file.close()
    else:
        print("URL名称已经存在!")

def pop():
    """创建一个删除信息函数"""
    input_pop_name = input("请输入你要删除的URL名称:")
    pop_call_find = find(input_pop_name)

    if pop_call_find[0] == 1:
        pop_file = open("D:\python\password.txt", "r")
        old_file = pop_file.readlines()

        write_file = open("D:\python\password.txt", "w")
        for temp in old_file:
            pop_content = eval(temp)
            if pop_content["URL名称:"] == input_pop_name:
                continue
            write_file.writelines(temp)

        pop_file.flush()
        write_file.flush()

        pop_file.close()
        write_file.close()
        print("文件已删除!")


    else:
        print("你要删除的文件不存在!")


def amend():
    """创建一个修改函数"""

    input_amend_name = input("请输入你要修改的URL名称:")
    amend_call_find = find(input_amend_name)

    if amend_call_find[0] == 1:
        input_amend_newname = input("请输入新的URL名称:")
        input_amend_newurl = input("请输入新的URL:")
        input_amend_newexplain = input("请输入新的URL说明:")
        new_amend_file = open("D:\python\[备份]password.txt", "a+")

        for old_file in content:
            old_file = eval(old_file)
            if old_file["URL名称:"] == input_amend_name:
                infors["URL名称:"] = input_amend_newname
                infors["URL:"] = input_amend_newurl
                infors["URL说明:"] = input_amend_newexplain
                new_content = str(infors) + "\n"
                new_amend_file.write(new_content)

                continue
            new_content = str(old_file) + "\n"
            new_amend_file.writelines(new_content)

        new_amend_file.close()
        url_file.close()
        file_name = os.path.basename("D:\python\password.txt")
        os.chdir("D:\python")
        os.remove("D:\python\password.txt")
        os.rename("[备份]password.txt",file_name)

    else:
        print("你要修改的文件不存在!")


def find(x):
    """创建一个查找函数工具,找到函数名称返回1 没找到返回0"""
    #input_find_name = input("请输入你要查找的URL名称:")
    input_find_name = x
    i = 0
    for eachline in content:
        str_content = eval(eachline)

        if str_content["URL名称:"] == input_find_name:
            i = 1
            return i , str_content
            #else:
            #return i , "没有数据"
    return i , "没有数据"



def find_true():
    """创建一个查找函数"""
    input_find_true_name = input("请输入你要查找的URL名称:")

    find_true_call = find(input_find_true_name)

    if find_true_call[0] == 1:
        print("URL名称:%s URL: %s URL说明:%s" %(find_true_call[1]["URL名称:"] , find_true_call[1]["URL:"] ,
                                            find_true_call[1]["URL说明:"]))
    else:
        print("您查找的函数不存在!")

def quit():
    print("感谢你的使用! -*- ")


def main():

    while True:
        print("")
        menu()
        print("")
        input_num = int(input("请输入功能号:"))

        if input_num == 1:
            add()
        elif input_num == 2:
            pop()
        elif input_num == 3:
            amend()
        elif input_num == 4:
            find_true()
        elif input_num == 5:
            quit()
            break
        else:
            print("请输入正确的功能号:")

main()

相关文章

  • python_密码本.py

  • Python函数的学习笔记_函数

    Python_函数 isinstance(a,int) #判断a是否为int If not (isinstance...

  • 分组密码工作模式

    电子密码本(ECB) 最简单的加密模式即为电子密码本(Electronic codebook,ECB)模式。需要加...

  • Python容器的学习笔记_容器

    Python_容器 my_str ='abcd\tc' # my_str[0]='Q' print(my_str)...

  • 文章链接集合

    作者:Gakki Python Python_查找字典中相同与不同的部分[https://www.jianshu....

  • Nginx 配置 Basic Auth

    环境准备 在开始之前,需要httpd-tools来生成密码本。 生成密码本 敲了该命令后,会提示输入密码 配置Ng...

  • 一次性密码本-绝对不会被破译的密码

    一次性密码本 一次性密码本即Vernam Cipher,是由Gilbert Vernam在1917年, 开发的一种...

  • 密码本

    前两天,我买了一个密码本。密码是保密的。它可以用来做算式题和记作业。外边的封皮是松鼠形状,拿着一根木头棍带一个叶子...

  • 密码本

    星期三的下午,妈妈给我们买了一个密码本,我的密码本的是蓝色的,上面画着绝地求生的图案,有两个战士,扛着枪很威武。本...

  • Python暴力破解wifi密码

    生成密码本 ​ 对于这个密码本就是我们常用的密码,一般是有数字、字母和符号组成。而现在呢?我们就用P...

网友评论

      本文标题:python_密码本.py

      本文链接:https://www.haomeiwen.com/subject/pjrabxtx.html