Sfoglia il codice sorgente

批量打标脚本

Signed-off-by: BinrenZhang <zhangbr@elab-plus.com>
BinrenZhang 4 anni fa
parent
commit
99523bac69
1 ha cambiato i file con 33 aggiunte e 7 eliminazioni
  1. 33 7
      test/http_test.py

+ 33 - 7
test/http_test.py

@@ -1,12 +1,13 @@
 import requests
-from mysql_db import MysqlDB
+import pymysql as ps
+
 headers_1 = {'content-type': "application/json", 'Authorization': 'APP appid = 4abf1a,token = 9480295ab2e2eddb8',
              'dsNo': 'source1'}
 headers_2 = {'content-type': "application/json",
              'Authorization': 'APP appid = 4abf1a,token = 9480295ab2e2eddb8',
              'dsNo': 'source2',
              'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, '
-                                             'like Gecko) Chrome/86.0.4240.111 Safari/537.36',
+                           'like Gecko) Chrome/86.0.4240.111 Safari/537.36',
              'Host': '101.132.43.32:5308',
              'POST': '/news/queryNewsByPage HTTP/1.1',
              'Connection': 'keep-alive',
@@ -14,16 +15,40 @@ headers_2 = {'content-type': "application/json",
              }
 
 
+class MysqlDB:
+    con = None
+    cursor = None
+
+    def __init__(self, db_name, ip, name, password):
+        self.db_name = db_name
+        self.con = ps.connect(host=ip, port=3306, user=name, password=password,
+                              db=self.db_name, charset='utf8')
+        self.cursor = self.con.cursor()
+
+    def select(self, sql, params=None):
+        if params:
+            self.cursor.execute(sql, params)
+        else:
+            self.cursor.execute(sql)
+        return self.cursor.fetchall()
+
+
 if __name__ == '__main__':
     import time
-    mysql = MysqlDB('marketing_db')
+    # 配置集团id
+    brand_id = 1
+    # 配置数据库连接信息
+    mysql = MysqlDB('marketing_db_prod', '106.14.204.123', 'kaifa', 'elab@123')
+    # 打标接口地址,
     url = "https://api-uat3.elaber.cn/elab-marketing-content/materialLabel/markingForMaterial"
+    # 需要打标物料的id
     sql_dict = {
-        1: 'select a.id from house a LEFT JOIN brand_house_rlat b on a.id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = 1',
-        2: 'select a.id from content_moment a LEFT JOIN brand_house_rlat b on a.house_id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = 1',
-        3: 'select a.id from t_content_album a LEFT JOIN brand_house_rlat b on a.house_id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = 1',
-        4: 'select a.id from content_layout a LEFT JOIN brand_house_rlat b on a.house_id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = 1'
+        1: 'select a.id from house a LEFT JOIN brand_house_rlat b on a.id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = {}'.format(brand_id),
+        2: 'select a.id from content_moment a LEFT JOIN brand_house_rlat b on a.house_id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = {}'.format(brand_id),
+        3: 'select a.id from t_content_album a LEFT JOIN brand_house_rlat b on a.house_id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = 1'.format(brand_id),
+        4: 'select a.id from content_layout a LEFT JOIN brand_house_rlat b on a.house_id = b.house_id where a.status = 1 and b.status = 1 and b.brand_id = 1'.format(brand_id)
     }
+    # 批量打标
     for index in sql_dict.keys():
         house = mysql.select(sql_dict.get(index))
         count = 0
@@ -38,4 +63,5 @@ if __name__ == '__main__':
             }
             response = requests.post(url, json=params, headers=headers_1)
             print(response.text)
+            # 每次请求后暂停下
             time.sleep(0.5)