{"id":200955,"date":"2025-05-06T08:50:52","date_gmt":"2025-05-06T00:50:52","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200955\/"},"modified":"2025-05-06T08:50:52","modified_gmt":"2025-05-06T00:50:52","slug":"python3-%e7%a8%8b%e5%ba%8f%e6%89%a7%e8%a1%8c%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e6%97%b6%e6%8a%a5%e9%94%99-%e5%a4%84%e7%90%86%e4%b8%ad-%ef%bc%9a%e5%a6%82","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200955\/","title":{"rendered":"Python3 \u7a0b\u5e8f\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u65f6\u62a5\u9519 \u201c \u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;\u201d\uff1a\u5982\u4f55\u89e3\u51b3\u6570\u636e\u5e93\u4e8b\u52a1\u95ee\u9898\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n<p>\u201d\uff1a\u5982\u4f55\u89e3\u51b3\u6570\u636e\u5e93\u4e8b\u52a1\u95ee\u9898\uff1f <\/p>\n<h1>Python3 \u7a0b\u5e8f\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u65f6\u62a5\u9519 \u201c<\/p>\n<p>\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n<p>\u201d\uff1a\u5982\u4f55\u89e3\u51b3\u6570\u636e\u5e93\u4e8b\u52a1\u95ee\u9898\uff1f <\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<\/p>\n<p>\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n<p>\u201d\uff1a\u5982\u4f55\u89e3\u51b3\u6570\u636e\u5e93\u4e8b\u52a1\u95ee\u9898\uff1f \u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230 \uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323313826741477633d04.jpg\" class=\"aligncenter\">\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n<p>\u201d\uff1a\u5982\u4f55\u89e3\u51b3\u6570\u636e\u5e93\u4e8b\u52a1\u95ee\u9898\uff1f &#8221; \/&gt; <\/p>\n<p><strong>python3 \u7a0b\u5e8f\u62a5\u9519<\/strong><\/p>\n<p>\u5728\u6267\u884c\u4e00\u6bb5\u4e1a\u52a1\u4ee3\u7801\u65f6\uff0c\u51fa\u73b0 \u201c&lt;p&gt;\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&lt;\/p&gt;\u201d \u7684\u9519\u8bef\u63d0\u793a\u3002<\/p>\n<p>\u7ecf\u8fc7\u6392\u67e5\uff0c\u53d1\u73b0\u4ee3\u7801\u4e2d\u7684\u6570\u636e\u5e93\u64cd\u4f5c\u90e8\u5206\u6709\u95ee\u9898\uff0c\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>import requests\nimport time\nimport json\nimport pymysql\n\nmydb = pymysql.connect(\n    host=\"92.68.40.12\", port=3306,\n    user=\"root\",\n    password=\"iss_root\",\n    database=\"dynamic_premium_db\"\n)\nmycursor = mydb.cursor()\n\ndef excute_sql_db(stratagy_id, city_id, app_name, total_price, over_flow_price, date_time):\n    sql = \"insert into over_flow_price(straragy_id,city_id,app_name,total_price,over_flow_price,time_stamp)values('%s','%s','%s','%s','%s','%s')\" % (stratagy_id, city_id, app_name, total_price, over_flow_price, date_time)\n    mycursor.execute(sql)  # \u62a5\u9519\u884c<\/pre>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>\u901a\u8fc7\u4ed4\u7ec6\u5206\u6790\u4ee3\u7801\uff0c\u53d1\u73b0\u4ee3\u7801\u4e2d\u7f3a\u5c11\u5bf9\u6570\u636e\u5e93\u4e8b\u52a1\u7684\u5904\u7406\u3002\u5728\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\uff0c\u7279\u522b\u662f\u6d89\u53ca\u5230\u591a\u4e2a\u8868\u7684\u64cd\u4f5c\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u4e8b\u52a1\u6765\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>def excute_sql_db(stratagy_id, city_id, app_name, total_price, over_flow_price, date_time):\n    sql = \"INSERT INTO over_flow_price(straragy_id,city_id,app_name,total_price,over_flow_price,time_stamp)VALUES('%s','%s','%s','%s','%s','%s')\" % (stratagy_id, city_id, app_name, total_price, over_flow_price, date_time)\n    try:\n        mycursor.execute(sql)\n        mydb.commit()  # \u63d0\u4ea4\u4e8b\u52a1\n        print('\u63d2\u5165\u6210\u529f')\n    except Exception as e:\n        mydb.rollback()  # \u56de\u6eda\u4e8b\u52a1\n        print('err: ' + sql)\n        print(e)<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPython3 \u7a0b\u5e8f\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u65f6\u62a5\u9519 \u201c<\/p>\n<p>\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n<p>\u201d\uff1a\u5982\u4f55\u89e3\u51b3\u6570\u636e\u5e93\u4e8b\u52a1\u95ee\u9898\uff1f \u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01 <\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5904\u7406\u4e2d&#8230;&#038;#8230&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200955","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200955"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200955\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}