material_label.py 3.3 KB

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