{"id":3336,"date":"2023-05-05T08:57:40","date_gmt":"2023-05-05T00:57:40","guid":{"rendered":"http:\/\/192.168.31.200\/?p=3336"},"modified":"2023-05-05T08:57:42","modified_gmt":"2023-05-05T00:57:42","slug":"%e7%88%ac%e5%8f%96%e6%9c%89%e9%81%93%e5%8d%95%e8%af%8d%e8%af%bb%e9%9f%b3python%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"http:\/\/xnw60rlg.ipyingshe.net:5347\/?p=3336","title":{"rendered":"\u722c\u53d6\u6709\u9053\u5355\u8bcd\u8bfb\u97f3Python\u4ee3\u7801"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># -*- coding: utf-8 -*-\r\n# @Time : 2022\/07\/19 22:00\r\n# @Author : Gordon\r\nimport os\r\nimport requests\r\nfrom pyquery import PyQuery as pq\r\nimport pandas as pd\r\nheaders={\"User-Agent\":\"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/103.0.0.0 Safari\/537.36\"}\r\ndef main():\r\n    try:\r\n        wordlist=get_wordlist()\r\n        print(wordlist)\r\n        look_up_words(wordlist)\r\n    except Exception as exc:\r\n        print(exc)\r\n\r\ndef get_wordlist():\r\n    \"\"\"\r\n    \u83b7\u53d6\u8bcd\u8868\r\n    \r\n    \"\"\"\r\n    ls=&#91;]\r\n    df = pd.read_excel(r\"C:\\Users\\cnliutz\\Documents\\python\\words.xlsx\")\r\n    data = df.to_dict('records')\r\n    #print(data)\r\n    for x in data:\r\n        ls.append(x&#91;\"list\"])\r\n        #print(ls)\r\n    return ls\r\ndef look_up_words(wordlist):\r\n    \"\"\"\r\n    \u722c\u53d6\u6709\u9053\u8bcd\u5178\u4e0a\u7684\u5355\u8bcd\u97f3\u6807\u3001\u8bcd\u4e49\u3001\u53d1\u97f3mp3\r\n    \r\n    \"\"\"\r\n    \r\n    for text in wordlist: #\u904d\u5386\u5355\u8bcd\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd\r\n        target_name=os.path.join(r\"C:\\Users\\cnliutz\\Documents\\python\",text+\".mp3\")\r\n        if os.path.exists(target_name):\r\n            pass\r\n        else: \r\n            try:\r\n                data = {\"audio\":text, \"lang\": \"zh\",\"type\":2} #\u5411\u6709\u9053\u6279\u91cf\u53d1\u8bf7\u6c42\uff0c\u5f97\u5230\u5355\u8bcd\u3001\u77ed\u8bed\u7684\u53d1\u97f3\r\n                resp = requests.post(\"https:\/\/dict.youdao.com\/dictvoice\", data=data,headers=headers)\r\n                with open(target_name,\"wb\") as f:\r\n                    f.write(resp.content)\r\n                if resp.status_code != 200:#\u5982\u679c\u65e0\u6cd5\u83b7\u53d6\u5230keyword\u6807\u7b7e\uff0c\u8bc1\u660e\u5355\u8bcd\u6ca1\u6709\u67e5\u5230\uff0c\u63d0\u9192\u5355\u8bcd\u4e0d\u5b58\u5728\u3002\r\n                    print(f\"{text}\u5355\u8bcd\u4e0d\u5b58\u5728\uff01\")\r\n                    with open(\"..\\missingwords.txt\",\"a+\",encoding=\"utf-8\") as f:\r\n                        f.write(text+\"\\n\")\r\n            except Exception as exc:\r\n                print(exc)\r\nif __name__ == '__main__':\r\n    main()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"941\" height=\"542\" src=\"http:\/\/192.168.31.200\/wp-content\/uploads\/2023\/05\/image.png\" alt=\"\" class=\"wp-image-3337\" srcset=\"http:\/\/xnw60rlg.ipyingshe.net:5347\/wp-content\/uploads\/2023\/05\/image.png 941w, http:\/\/xnw60rlg.ipyingshe.net:5347\/wp-content\/uploads\/2023\/05\/image-300x173.png 300w, http:\/\/xnw60rlg.ipyingshe.net:5347\/wp-content\/uploads\/2023\/05\/image-768x442.png 768w\" sizes=\"auto, (max-width: 941px) 100vw, 941px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-3336","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3336"}],"version-history":[{"count":1,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3336\/revisions"}],"predecessor-version":[{"id":3338,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3336\/revisions\/3338"}],"wp:attachment":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3336"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}