{"id":2935,"date":"2023-12-19T10:52:18","date_gmt":"2023-12-19T02:52:18","guid":{"rendered":"https:\/\/www.tra56.com\/?p=2935"},"modified":"2023-12-19T10:52:18","modified_gmt":"2023-12-19T02:52:18","slug":"2935","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/2935.html","title":{"rendered":"\u600e\u4e48\u7528Python\u5b9e\u73b0\u5fae\u4fe1\u81ea\u52a8\u56de\u590d,\u4e0d\u662fitchat\u5b9e\u73b0, \u4e0d\u662fitchat\u5b9e\u73b0, \u4e0d\u662fitchat\u5b9e\u73b0"},"content":{"rendered":"
#\u6839\u636e\u9884\u5b9a\u7684csv\u6570\u636e\u81ea\u52a8\u56de\u590d\r\nimport numpy as np\r\nimport pandas as pd\r\nfrom uiautomation import WindowControl\r\nimport time\r\nimport requests\r\n# \u7ed1\u5b9a\u5fae\u4fe1\u4e3b\u7a97\u53e3\r\nwx = WindowControl(Name='\u5fae\u4fe1', searchDepth=1)   #searchDepth=1\u53c2\u6570\u6307\u5b9a\u5728\u67e5\u627e\u7a97\u53e3\u65f6\u53ea\u641c\u7d22\u76f4\u63a5\u5b50\u7ea7\u7a97\u53e3\uff0c\u4ee5\u63d0\u9ad8\u67e5\u627e\u6548\u7387\r\n# \u5207\u6362\u7a97\u53e3\r\nwx.ListControl()\r\nwx.SwitchToThisWindow()#ListControl()\u65b9\u6cd5\u7528\u4e8e\u5217\u51fa\u6240\u6709\u5b50\u7ea7\u7a97\u53e3\uff0c\u800cSwitchToThisWindow()\u65b9\u6cd5\u5219\u5c06\u7126\u70b9\u5207\u6362\u5230\u5fae\u4fe1\u4e3b\u7a97\u53e3\r\n# \u5bfb\u627e\u4f1a\u8bdd\u63a7\u4ef6\u7ed1\u5b9a\r\nhw = wx.ListControl(Name='\u4f1a\u8bdd')\r\n# \u901a\u8fc7pd\u8bfb\u53d6\u6570\u636e\r\ndf = pd.read_csv('\u56de\u590d\u6570\u636e.csv', encoding='utf-8')\r\nprint(df)\r\n \r\nconversations = hw.GetChildren()  # GetChildren()\u65b9\u6cd5\uff0c\u83b7\u53d6\u4f1a\u8bdd\u5217\u8868\u4e2d\u7684\u6240\u6709\u5b50\u63a7\u4ef6\u3002\r\njilu_num = 0\r\nfor conversation in conversations:\r\n    contact_name = conversation.Name\r\n    if contact_name == '\u6c34\u679c\u5de8\u4ea8':   #\u6539\u6210\u4f60\u60f3\u56de\u590d\u7684\u8054\u7cfb\u4eba\u7684\u540d\u5b57\r\n        conversation.Click(simulateMove=False)\r\n        message_list = wx.ListControl(Name='\u6d88\u606f').GetChildren()  # \u83b7\u53d6\u6d88\u606f\u5217\u8868\u4e2d\u7684\u6240\u6709\u5b50\u63a7\u4ef6\r\n        jilu_num = len(message_list)\r\n        print(f"\u539f\u672c\u6709{jilu_num}\u6761\u6d88\u606f")\r\n# \u6b7b\u5faa\u73af\u63a5\u6536\u6d88\u606f\r\nwhile True:\r\n    for conversation in conversations:\r\n        contact_name = conversation.Name\r\n        if contact_name == '\u6c34\u679c\u5de8\u4ea8':\r\n            #conversation.Click(simulateMove=False)\r\n            message_list = wx.ListControl(Name='\u6d88\u606f').GetChildren()  # \u83b7\u53d6\u6d88\u606f\u5217\u8868\u4e2d\u7684\u6240\u6709\u5b50\u63a7\u4ef6\r\n            new_msg_num = len(message_list)-jilu_num\r\n            if new_msg_num != 0:\r\n                print(f"\u6709{new_msg_num}\u6761\u65b0\u6d88\u606f\uff1a")\r\n                for i in range(jilu_num, len(message_list)):\r\n                    print(f"\u6b63\u5728\u56de\u590d\u7b2c{i+1}\u6761\u6d88\u606f")\r\n                    #\u5904\u7406\u6bcf\u4e00\u6761\u6d88\u606f\r\n                    every_msg = message_list[i].Name\r\n                    ##########\r\n                    # \u5224\u65ad\u5173\u952e\u5b57\r\n                    msg = df.apply(lambda x: x['\u56de\u590d\u5185\u5bb9'] if x['\u5173\u952e\u8bcd'] in every_msg else None, axis=1)\r\n                    # \u8fd4\u56de\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u5305\u542b\u5904\u7406\u7ed3\u679c\u7684Series\u5bf9\u8c61\uff0cmsg\u548c\u5217\u8868\u5dee\u4e0d\u591a\r\n                    print(f"\u5339\u914d\u5230\u7684\u56de\u590d\u5185\u5bb9\uff1a{msg}")\r\n                    msg.dropna(axis=0, how='any', inplace=True)  # \u8fd9\u884c\u4ee3\u7801\u79fb\u9664\u56de\u590d\u5185\u5bb9\u4e2d\u7684\u7a7a\u6570\u636e\uff08NaN\u503c\uff09\r\n                    ar = np.array(msg).tolist()  # \u8fd9\u884c\u4ee3\u7801\u5c06\u7b5b\u9009\u540e\u7684\u56de\u590d\u5185\u5bb9\u8f6c\u6362\u4e3a\u5217\u8868\r\n                    # \u80fd\u591f\u5339\u914d\u5230\u6570\u636e\u65f6\r\n                    if ar:\r\n                        # \u5c06\u6570\u636e\u8f93\u5165\r\n                        # \u66ff\u6362\u6362\u884c\u7b26\u53f7\r\n                        wx.SendKeys(ar[0].replace('{br}', '{Shift}{Enter}'), waitTime=0)\r\n                        # \u53d1\u9001\u6d88\u606f\uff0c\u56de\u8f66\u952e\r\n                        wx.SendKeys('{Enter}', waitTime=1)\r\n                        # \u901a\u8fc7\u6d88\u606f\u5339\u914d\u68c0\u7d22\u4f1a\u8bdd\u680f\u7684\u8054\u7cfb\u4eba\r\n                        print(f"\u56de\u590d\u5185\u5bb9\u662f {ar[0]}")\r\n                        #wx.TextControl(SubName=ar[0][:5]).RightClick()\r\n                        # break\r\n                    #########\u4e0d\u80fd\u5339\u914d\u5230\u6570\u636e\uff0c\u7528\u673a\u5668\u4eba\u56de\u590d\r\n                    else:\r\n                        wx.SendKeys('\u4e0d\u77e5\u9053\u4f60\u5728\u8bf4\u4ec0\u4e48', waitTime=0)\r\n                        wx.SendKeys('{Enter}', waitTime=0)\r\n                jilu_num = len(message_list) + 1\r\n                print(f"\u73b0\u5728\u4e00\u5171\u6709{jilu_num}\u6761\u6d88\u606f")\r\n            else:\r\n                print("\u6ca1\u6709\u65b0\u6d88\u606f")<\/pre>\n

\u6570\u636e\u683c\u5f0f<\/p>\n

\"image.png\"\/<\/p>\n

\"image.png\"\/<\/p>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

#\u6839\u636e\u9884\u5b9a\u7684csv\u6570\u636e\u81ea\u52a8\u56de\u590d import numpy as np impor […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-2935","post","type-post","status-publish","format-standard","hentry","category-python3"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2935"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=2935"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2935\/revisions"}],"predecessor-version":[{"id":2936,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2935\/revisions\/2936"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=2935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=2935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=2935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}