material_label.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. """
  31. 1:修改下列配置信息
  32. 2:执行命令 python material_label.py
  33. """
  34. import time
  35. api_path_online = 'http://101.132.79.13:5308/materialLabel/markingForMaterial'
  36. api_path_uat3 = '"https://api-uat3.elaber.cn/elab-marketing-content/materialLabel/markingForMaterial"'
  37. api_path_test = 'http://101.132.138.87:5555/elab-marketing-content/materialLabel/markingForMaterial'
  38. api_path_test2 = 'http://106.14.187.241:5555/elab-marketing-content//materialLabel/markingForMaterial'
  39. # 1. 配置集团id
  40. brand_id = 46
  41. # 2. 配置数据库连接信息
  42. mysql = MysqlDB('marketing_db', '106.15.201.221', 'kaifa', 'elab@123')
  43. # 3. 打标接口地址
  44. url = api_path_test2
  45. # 需要打标物料的id
  46. sql_dict = {
  47. 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(
  48. brand_id),
  49. 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(
  50. brand_id),
  51. 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 = {}'.format(
  52. brand_id),
  53. 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 = {}'.format(
  54. brand_id)
  55. }
  56. material_dict = {
  57. 1: '项目',
  58. 2: '视频',
  59. 3: '图集',
  60. 4: '户型'
  61. }
  62. # 批量打标
  63. for index in sql_dict.keys():
  64. house = mysql.select(sql_dict.get(index))
  65. count = 0
  66. for x in house:
  67. params = {
  68. "deleteStatus": 2,
  69. "materialId": x[0],
  70. # 物料类型,1:项目,2:视频,3:图集(图片),4:户型
  71. "materialType": index,
  72. "user": ":wq"
  73. }
  74. response = requests.post(url, json=params, headers=headers_1)
  75. print(material_dict.get(index), str(x[0]), '打标结果:', response.text)
  76. # 每次请求后暂停下
  77. time.sleep(0.5)