{"id":1605,"date":"2023-02-14T15:01:37","date_gmt":"2023-02-14T07:01:37","guid":{"rendered":"http:\/\/zhang.mba\/?p=1605"},"modified":"2023-02-14T15:12:34","modified_gmt":"2023-02-14T07:12:34","slug":"du-shencku-zi-dong-sheng-chengpython-api-han-shu-j","status":"publish","type":"post","link":"https:\/\/zhang.mba\/index.php\/2023\/02\/14\/15\/01\/37\/1605\/du-shencku-zi-dong-sheng-chengpython-api-han-shu-j\/python\/zhangzhiqi\/","title":{"rendered":"\u5ea6\u7533C#\u5e93\u81ea\u52a8\u751f\u6210Python API\u51fd\u6570\u63a5\u53e3"},"content":{"rendered":"<h2><a id=\"%E5%89%8D%E8%A8%80\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u524d\u8a00<\/h2>\n<p>\u5728\u5ea6\u7533\u63d0\u4f9b\u7684SDK\u4e2d\u6709\u4e00\u4e2aXML\u6587\u4ef6\uff0c\u91cc\u9762\u8be6\u7ec6\u8bf4\u660e\u4e86C#\u5e93\u4e2d\u5404\u4e2aAPI\u63a5\u53e3\u7684\u529f\u80fd\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763582625596.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763582625596.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><br \/>\nAPI\u63a5\u53e3\u90fd\u5b9a\u4e49\u5728DVPCamera\u8fd9\u4e2a\u7c7b\u4e2d\uff0c\u5927\u6982\u67092000\u591a\u884c\uff0c200\u591a\u4e2a\u63a5\u53e3<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763582888511.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763582888511.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2><a id=\"%E6%80%9D%E8%B7%AF\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u601d\u8def<\/h2>\n<p>\u7531\u4e8ePython\u662f\u5f31\u7c7b\u578b\u7684\u8bed\u8a00\uff0c\u4e0d\u9700\u8981\u7c7b\u578b\u5b9a\u4e49\uff0c\u4e8e\u662f\u8fd9\u5c31\u4e3a\u81ea\u52a8\u8f6c\u6362\u63d0\u4f9b\u4e86\u65b9\u4fbf\uff0c\u89c2\u5bdfC#\u7684\u63a5\u53e3\u7ed3\u6784\uff0c\u53ef\u4ee5\u5c06\u4fe1\u606f\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b\uff1a\u51fd\u6570\u529f\u80fd\u8bf4\u660e\uff0c\u5f62\u53c2\u82f1\u6587\u53d8\u91cf\u540d\uff0c\u5f62\u53c2\u4e2d\u6587\u89e3\u91ca\uff0c\u51fd\u6570\u540d\uff0c\u8fd4\u56de\u503c\u4e2d\u6587\u89e3\u91ca\u7b49<br \/>\n\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5206\u522b\u5c06\u8fd9\u51e0\u7c7b\u4fe1\u606f\u63d0\u53d6\u51fa\u6765\uff0c\u7136\u540e\u653e\u5230\u51c6\u5907\u597d\u7684Python\u51fd\u6570\u6a21\u677f\u4e2d\u5c31\u53ef\u4ee5\u4e86\uff0cPython\u7684\u51fd\u6570\u683c\u5f0f\u5982\u4e0b\uff0c\u53ea\u9700\u8981\u66ff\u6362\u67d0\u4e9b\u4fe1\u606f\u5373\u53ef\uff1a<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763586166354.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763586166354.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2><a id=\"%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4ee3\u7801\u5b9e\u73b0<\/h2>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">#  \/\/  X:\/\u8f6f\u4ef6\/C#\u5e93\u8c03\u7528\u6d4b\u8bd5\/\u81ea\u52a8\u5316API\u751f\u6210\u4e4b\u5b8c\u6574\u6d41\u7a0b.py\n#  \/\/  Copyright (c) 2023.\n#  \/\/  @Time    : 2023\/2\/14   13:35:44\n#  \/\/  @Author : \u5f20\u7a1a\u7426\n#  \/\/  @Address: \u6e56\u5317\u7406\u5de5\u5b66\u9662\u817e\u9f99\u516c\u5bd3 6131\n#  \/\/  @Email   : zhang@zhang.mba \/ zhangzhiqi828@gmail.com \/ zhangzhiqi@lh83.onmicrosoft.com \/ 2272358828@qq.com\n#  \/\/  @File      : \u81ea\u52a8\u5316API\u751f\u6210\u4e4b\u5b8c\u6574\u6d41\u7a0b.py\n#  \/\/  @LastModified: 2023\/2\/14 \u4e0b\u53481:35\n#  \/\/  @ProjectName : C#\u5e93\u8c03\u7528\u6d4b\u8bd5\nimport re\n\nwith open('text.txt', 'r', encoding='utf-8') as f:\n    text = f.read()\n\nsections = text.strip().split('\\n\\n')\nall=&quot;&quot;\n# \u8f93\u51fa\u7ed3\u679c\nfor section in sections:\n    # print(section)\n    # print('*'*50)\n\n    #\u63d0\u53d6\u51fd\u6570\u540d \u548c \u5f62\u53c2\u5217\u8868\n    pattern = r'(\\w+)\\s*\\((.*?)\\);'\n    match = re.search(pattern, section)\n\n    if match:\n        # \u63d0\u53d6\u51fd\u6570\u540d\u548c\u5f62\u53c2\u53d8\u91cf\u540d\n        func_name = match.group(1)\n        params = match.group(2)\n        # \u53bb\u9664\u7a7a\u683c\u548c\u6362\u884c\u7b26\n        params = re.sub(r'\\s+', '', params)\n        # \u5206\u5272\u5f62\u53c2\u53d8\u91cf\u540d\n        param_names = params.split(',')\n        # print('Function name:', func_name)\n        # print('Parameter names:', param_names)\n\n    # \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6param\u6807\u7b7e\u4e2d\u7684\u6587\u5b57\n    param_list = re.findall(r'&lt;param name=&quot;.*?&quot;&gt;(.*?)&lt;\/param&gt;', section, re.DOTALL)\n\n    # print(param_list)\n    # \u63d0\u53d6\u8fd4\u56de\u503c\u8bf4\u660e\n    returns = re.findall(r'&lt;returns&gt;(.*?)&lt;\/returns&gt;', section)\n    if not returns:\n        returns=[&quot;&quot;]\n    # print(returns)\n\n    #\u63d0\u53d6para\u8bf4\u660e\n    result = re.findall(r&quot;&lt;para&gt;(.*?)&lt;\/para&gt;&quot;, section, flags=re.S)\n    # print(result)\n\n    #\u63d0\u53d6\u51fd\u6570\u8bf4\u660e\n    summary_pattern = r'&lt;summary&gt;(.+?)&lt;\\\/summary&gt;'\n    match = re.search(summary_pattern, section, flags=re.DOTALL)\n\n    if match:\n        summary_text = match.group(1).strip()\n        # print(summary_text)\n        lines = summary_text.split('\\n')\n        first_line = lines[0].replace('\/\/\/', '').strip()\n        # print(first_line)\n\n    result1=[f'{x}:{y}\\n'for x,y in zip(param_names,param_list)]\n    # print(result1)\n    tmp=&quot;\\t:param &quot;+&quot;\\t:param &quot;.join(result1)\n    # print(tmp)\n    all+=f'\\ndef {func_name}(self,{&quot;,&quot;.join(param_names)}):\\n\\t&quot;&quot;&quot;\\n\\t{first_line}\\n{tmp}\\t:return:{returns[0]}\\n\\t&quot;&quot;&quot;\\n\\treturn self.instance.{func_name}({&quot;,&quot;.join(param_names)})\\n'\n    # print(all)\n#\u5199\u5165\u6587\u4ef6\u4e2d\nwith open('success.txt', 'w', encoding='utf-8') as f:\n    f.write(all)\n\n<\/code><\/pre>\n<h2><a id=\"%E8%BD%AC%E6%8D%A2%E5%90%8E%E7%9A%84%E6%95%88%E6%9E%9C\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u8f6c\u6362\u540e\u7684\u6548\u679c<\/h2>\n<p>\u6548\u679c\u5982\u4e0b\uff1a<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763587287792.jpg'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"http:\/\/zhang.mba\/wp-content\/uploads\/2023\/02\/16763587287792.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5728\u5ea6\u7533\u63d0\u4f9b\u7684SDK\u4e2d\u6709\u4e00\u4e2aXML\u6587\u4ef6\uff0c\u91cc\u9762\u8be6\u7ec6\u8bf4\u660e\u4e86C#\u5e93\u4e2d\u5404\u4e2aAPI\u63a5\u53e3\u7684\u529f\u80fd\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c API\u63a5\u53e3\u90fd\u5b9a\u4e49\u5728DVPCamera\u8fd9\u4e2a\u7c7b\u4e2d\uff0c\u5927\u6982\u67092000\u591a\u884c\uff0c200\u591a\u4e2a\u63a5\u53e3 \u601d\u8def \u7531\u4e8ePython\u662f\u5f31\u7c7b\u578b\u7684\u8bed\u8a00\uff0c\u4e0d\u9700\u8981\u7c7b\u578b\u5b9a\u4e49\uff0c\u4e8e\u662f\u8fd9\u5c31\u4e3a\u81ea\u52a8\u8f6c\u6362\u63d0\u4f9b\u4e86\u65b9\u4fbf\uff0c\u89c2\u5bdfC# &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[46,12],"tags":[],"_links":{"self":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1605"}],"collection":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/comments?post=1605"}],"version-history":[{"count":0,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1605\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/media?parent=1605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/categories?post=1605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/tags?post=1605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}