{"id":499,"date":"2018-07-25T07:26:22","date_gmt":"2018-07-25T07:26:22","guid":{"rendered":"http:\/\/www.liutianfeng.com\/?p=499"},"modified":"2018-07-25T07:35:27","modified_gmt":"2018-07-25T07:35:27","slug":"%e6%a0%b9%e6%8d%ae%e9%80%89%e6%8b%a9-%e7%99%bb%e5%bd%95%e4%b8%8d%e5%90%8c%e8%b4%a6%e5%8f%b7-%e6%98%be%e7%a4%ba%e4%b8%8d%e5%90%8c%e9%a1%b5%e9%9d%a2%e7%9a%84python%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.liutianfeng.com\/?p=499","title":{"rendered":"\u6839\u636e\u9009\u62e9, \u767b\u5f55\u4e0d\u540c\u8d26\u53f7, \u663e\u793a\u4e0d\u540c\u9875\u9762\u7684Python\u811a\u672c"},"content":{"rendered":"<p>\u9700\u6c42:<\/p>\n<ul>\n<li>\u6839\u636e\u5217\u8868, \u9009\u62e9\u8981\u767b\u5f55\u7684\u9875\u9762;<\/li>\n<li>\u6839\u636e\u4e0d\u540c\u7684\u9875\u9762, \u9009\u62e9\u4e0d\u540c\u7684\u767b\u5f55\u8d26\u53f7, \u8d26\u53f7\u591a\u4e2a, \u53ef\u4ee5\u5faa\u73af;<\/li>\n<li>\u767b\u5f55\u4ee5\u540e\u7684\u72b6\u6001\u53ef\u4ee5\u4fdd\u7559, \u5728\u9000\u51fa\u540e\u53d8\u4e3aFalse, \u4e0b\u6b21\u518d\u6b21\u767b\u5f55;<\/li>\n<\/ul>\n<p>\u6211\u4eec\u8fd9\u91cc\u7528\u4e86jingdong\u548cweixin\u4e24\u6279\u8d26\u53f7, \u6bcf\u6279\u8d26\u53f7\u53ef\u4ee5\u6709\u591a\u4e2a, \u5199\u5728\u6587\u4ef6\u4e2d; \u6839\u636e\u4e0d\u540c\u7684\u9009\u62e9, \u663e\u793a\u4e0d\u540c\u7684\u9875\u9762: Home, Fiance, Book.<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\"># _Author: lWX548594\r\n# _Date: 2018\/7\/23 0023\r\n# _ScriptName: login\r\n\r\ndef read_jingdong():   # \u5b9a\u4e49\u8bfb\u53d6jingdong\u8d26\u53f7\u7684\u51fd\u6570\r\n    global line\r\n    line = {}\r\n    f = open(\"jingdong\", 'r+')\r\n    for lines in f:\r\n        key, value = lines.strip().split()\r\n        line[key] = value\r\n\r\ndef read_weixin():   # \u5b9a\u4e49\u8bfb\u53d6\u5fae\u4fe1\u8d26\u53f7\u7684\u51fd\u6570\r\n    global line\r\n    line = {}\r\n    f = open(\"weixin\", 'r+')\r\n    for lines in f:\r\n        key, value = lines.strip().split()\r\n        line[key] = value\r\n\r\ndef init():         # \u521d\u59cb\u5316\u51fd\u6570\r\n    pages = ['Home', 'Fiance', 'Book']\r\n    for i in enumerate(pages, 1):\r\n        print(i)\r\n\r\n    choice = input(\"Please input your choice, q for quit: \")\r\n    while True:\r\n        if choice == 'q':\r\n            print(\"Exit..........\")\r\n            file3 = open('auth_file', 'w')\r\n            file3.write('False')     # q\u9000\u51fa, \u5c06auth_file\u6587\u4ef6\u5199\u5165False, \u6ce8\u610f, \u8fd9\u662f\u5b57\u7b26\u4e32\u683c\u5f0f, \u4e0d\u662fbool\u683c\u5f0f.\r\n            exit()\r\n        elif not choice.isdigit():\r\n            print(\"Please input a number.\")\r\n            choice = input(\"Please input your choice: \")\r\n        elif int(choice) not in range(1, 4):\r\n            print(\"Out of range...\")\r\n            exit()\r\n        else:\r\n            break\r\n    global page_choice      # \u51fd\u6570\u4e2d\u7684\u53d8\u91cf, \u901a\u5e38\u9700\u8981\u58f0\u660e\u4e00\u4e0b\u5168\u5c40, \u5426\u5219\u5176\u4ed6\u51fd\u6570\u8c03\u7528\u4e0d\u4e86, \u76ee\u524d\u5b66\u7684\u5c11, \u4ee5\u540e\u53ef\u80fd\u6709\u66f4\u597d\u7684\u65b9\u6cd5.\r\n    if choice == '1':\r\n        page_choice = \"Home\"\r\n        read_jingdong()     # \u6839\u636e\u4e0d\u540c\u7684\u9875\u9762, \u9009\u62e9\u8bfb\u5165\u4e0d\u540c\u7684\u8d26\u53f7\r\n    elif choice == '2':\r\n        page_choice = \"Fiance\"\r\n        read_weixin()\r\n    elif choice == '3':\r\n        page_choice = \"Book\"\r\n        read_jingdong()\r\n    else:\r\n        pass\r\n    auth_file = open('auth_file', 'r')\r\n    global auth_type\r\n    auth_type = auth_file.readline()\r\n    print(\"auth_type: %s\" % auth_type)\r\n\r\n\r\ndef which_flag(flag):     # \u88c5\u9970\u5668, \u4f20\u5165\u4e00\u4e2aflag, \u6765\u786e\u5b9a\u662f\u5426\u767b\u5f55\r\n    def login(f):\r\n        def inner(a_choice):\r\n            print(\"Flag: %s\" % flag)\r\n            if flag == 'False':     # \u5b57\u7b26\u4e32\u683c\u5f0f, \u4e0d\u662fbool...\r\n                print(\"You have to login first...\")\r\n                while True:\r\n                    my_username = input(\"Please input your username: \")\r\n                    my_pass = input(\"Please input your password: \")\r\n                    for i in line.keys():     # \u5faa\u73af\u9a8c\u8bc1\u7528\u6237\r\n                        break_flag = False\r\n                        if i == my_username:\r\n                            if line[i] == my_pass:\r\n                                print(\"Login successfully...\")\r\n                                file2 = open('auth_file', 'w')\r\n                                file2.write('True')    # \u6210\u529f\u540e\u5c06auth_file\u5199\u5165True\r\n                                break_flag = True\r\n                                break\r\n                    else:\r\n                        print(\"Wrong username or password. Please try again.\")    # \u6240\u6709\u8d26\u6237\u9a8c\u8bc1\u5931\u8d25, \u663e\u793a\u63d0\u793a\u4fe1\u606f\r\n                    if break_flag:\r\n                        break\r\n            f(a_choice)\r\n        return inner\r\n    return login\r\n\r\nwhile True:    # \u5faa\u73af\u5f00\u59cb\u8fdb\u884c\u9875\u9762\u663e\u793a\r\n    init()\r\n    @which_flag(auth_type)\r\n    def show_page(my_choice):\r\n        print(\"This is %s page...\" % my_choice)\r\n    show_page(page_choice)<\/code><\/pre>\n<p>\u5176\u4e2d, weixin\u548cjingdong\u4e24\u4e2a\u8d26\u53f7\u5bc6\u7801\u6587\u4ef6\u683c\u5f0f\u5982\u4e0b:<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">lius 7788\r\nlius1 7788\r\nlius2 7788<\/code><\/pre>\n<p>auth_file\u91cc\u9762\u4e8b\u5148\u5199\u5165False:<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">False<\/code><\/pre>\n<p>\u811a\u672c\u8fd0\u884c\u7ed3\u679c\u5c55\u793a:<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">C:\\Users\\lwx548594\\PycharmProjects\\LiusProject\\venv\\Scripts\\python.exe C:\/Users\/lwx548594\/PycharmProjects\/LiusProject\/Day17\/login.py\r\n(1, 'Home')\r\n(2, 'Fiance')\r\n(3, 'Book')\r\nPlease input your choice, q for quit: 1\r\nauth_type: False\r\nFlag: False\r\nYou have to login first...\r\nPlease input your username: lius\r\nPlease input your password: 7788\r\nLogin successfully...\r\nThis is Home page...\r\n(1, 'Home')\r\n(2, 'Fiance')\r\n(3, 'Book')\r\nPlease input your choice, q for quit: 3\r\nauth_type: True\r\nFlag: True\r\nThis is Book page...\r\n(1, 'Home')\r\n(2, 'Fiance')\r\n(3, 'Book')\r\nPlease input your choice, q for quit: 2\r\nauth_type: True\r\nFlag: True\r\nThis is Fiance page...\r\n(1, 'Home')\r\n(2, 'Fiance')\r\n(3, 'Book')\r\nPlease input your choice, q for quit: q\r\nExit..........\r\n\r\nProcess finished with exit code 0<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u811a\u672c\u662f\u81ea\u5df1\u778e\u5199\u7684, \u6709\u4e0d\u5bf9\u7684\u5730\u65b9, \u8bf7\u5927\u5bb6\u6307\u6b63.<\/p>\n<p>&nbsp;<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.liutianfeng.com\">liutianfeng.com<\/a> &raquo; <a href=\"https:\/\/www.liutianfeng.com\/?p=499\">\u6839\u636e\u9009\u62e9, \u767b\u5f55\u4e0d\u540c\u8d26\u53f7, \u663e\u793a\u4e0d\u540c\u9875\u9762\u7684Python\u811a\u672c<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42: \u6839\u636e\u5217\u8868, \u9009\u62e9\u8981\u767b\u5f55\u7684\u9875\u9762; \u6839\u636e\u4e0d\u540c\u7684\u9875\u9762, \u9009\u62e9\u4e0d\u540c\u7684\u767b\u5f55\u8d26\u53f7, \u8d26\u53f7\u591a\u4e2a, \u53ef\u4ee5\u5faa\u73af; \u767b\u5f55\u4ee5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[32],"tags":[],"_links":{"self":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/499"}],"collection":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=499"}],"version-history":[{"count":3,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":502,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions\/502"}],"wp:attachment":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}