material_label.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. # 配置集团id
  36. brand_id = 1
  37. # 配置数据库连接信息
  38. mysql = MysqlDB('marketing_db_prod', '106.14.204.123', 'kaifa', 'elab@123')
  39. # 打标接口地址,
  40. url = "https://api-uat3.elaber.cn/elab-marketing-content/materialLabel/markingForMaterial"
  41. # 需要打标物料的id
  42. sql_dict = {
  43. 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(
  44. brand_id),
  45. 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(
  46. brand_id),
  47. 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(
  48. brand_id),
  49. 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(
  50. brand_id)
  51. }
  52. material_dict = {
  53. 1: '项目',
  54. 2: '视频',
  55. 3: '图集',
  56. 4: '户型'
  57. }
  58. # 批量打标
  59. for index in sql_dict.keys():
  60. house = mysql.select(sql_dict.get(index))
  61. count = 0
  62. for x in house:
  63. params = {
  64. "deleteStatus": 2,
  65. "materialId": x[0],
  66. # 物料类型,1:项目,2:视频,3:图集(图片),4:户型
  67. "materialType": index,
  68. "user": "batch20201230"
  69. }
  70. response = requests.post(url, json=params, headers=headers_1)
  71. print(material_dict.get(index), str(x[0]), '打标结果:', response.text)
  72. # 每次请求后暂停下
  73. time.sleep(0.5)