http_test.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import requests
  2. import pymysql as ps
  3. headers_1 = {'content-type': "application/json", 'Authorization': 'APP appid = 4abf1a,token = 9480295ab2e2eddb8',
  4. 'dsNo': 'source1'}
  5. headers_2 = {'content-type': "application/json",
  6. 'Authorization': 'APP appid = 4abf1a,token = 9480295ab2e2eddb8',
  7. 'dsNo': 'source2',
  8. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, '
  9. 'like Gecko) Chrome/86.0.4240.111 Safari/537.36',
  10. 'Host': '101.132.43.32:5308',
  11. 'POST': '/news/queryNewsByPage HTTP/1.1',
  12. 'Connection': 'keep-alive',
  13. 'Accept': 'application/json;charset=UTF-8'
  14. }
  15. class MysqlDB:
  16. con = None
  17. cursor = None
  18. def __init__(self, db_name, ip, name, password):
  19. self.db_name = db_name
  20. self.con = ps.connect(host=ip, port=3306, user=name, password=password,
  21. db=self.db_name, charset='utf8')
  22. self.cursor = self.con.cursor()
  23. def select(self, sql, params=None):
  24. if params:
  25. self.cursor.execute(sql, params)
  26. else:
  27. self.cursor.execute(sql)
  28. return self.cursor.fetchall()
  29. if __name__ == '__main__':
  30. import time
  31. # 配置集团id
  32. brand_id = 1
  33. # 配置数据库连接信息
  34. mysql = MysqlDB('marketing_db_prod', '106.14.204.123', 'kaifa', 'elab@123')
  35. # 打标接口地址,
  36. url = "https://api-uat3.elaber.cn/elab-marketing-content/materialLabel/markingForMaterial"
  37. # 需要打标物料的id
  38. sql_dict = {
  39. 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),
  40. 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),
  41. 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),
  42. 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)
  43. }
  44. # 批量打标
  45. for index in sql_dict.keys():
  46. house = mysql.select(sql_dict.get(index))
  47. count = 0
  48. for x in house:
  49. print(x[0])
  50. params = {
  51. "deleteStatus": 2,
  52. "materialId": x[0],
  53. # 物料类型,1:项目,2:视频,3:图集(图片),4:户型
  54. "materialType": index,
  55. "user": "batch20201230"
  56. }
  57. response = requests.post(url, json=params, headers=headers_1)
  58. print(response.text)
  59. # 每次请求后暂停下
  60. time.sleep(0.5)