weixinzhishu.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/2/10
  4. from datetime import date, timedelta
  5. import requests
  6. import json
  7. from common.feishu import Feishu
  8. class Weixinzhishu:
  9. @classmethod
  10. def search_word(cls):
  11. return ["消息", "彻底", "现在", "真是", "突然", "消失", "太好了", "心声"]
  12. @classmethod
  13. def wechat_key(cls, log_type, crawler):
  14. sheet = Feishu.get_values_batch(log_type, crawler, 'sVL74k')
  15. for i in range(len(sheet)):
  16. search_key = sheet[1][1]
  17. openid = sheet[1][2]
  18. return search_key, openid
  19. @classmethod
  20. def weixinzhishu(cls, log_type, crawler):
  21. search_word_list = cls.search_word()
  22. wechat_key = cls.wechat_key(log_type, crawler)
  23. search_key = wechat_key[0]
  24. openid = wechat_key[-1]
  25. start_ymd = (date.today() + timedelta(days=-1)).strftime("%Y-%m-%d").replace("-", "")
  26. end_ymd = (date.today() + timedelta(days=-8)).strftime("%Y-%m-%d").replace("-", "")
  27. print(f"search_key:{search_key}")
  28. print(f"openid:{openid}")
  29. print(f"start_ymd:{start_ymd}")
  30. print(f"start_ymd:{end_ymd}")
  31. for word in search_word_list:
  32. print(f"word:{word}")
  33. url = "https://search.weixin.qq.com/cgi-bin/wxaweb/wxindex"
  34. payload = json.dumps({
  35. "openid": openid,
  36. "search_key": search_key,
  37. "cgi_name": "GetDefaultIndex",
  38. "start_ymd": start_ymd,
  39. "end_ymd": end_ymd,
  40. "query": word
  41. })
  42. headers = {
  43. 'Host': 'search.weixin.qq.com',
  44. 'content-type': 'application/json',
  45. 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.32(0x1800202a) NetType/WIFI Language/zh_CN',
  46. 'Referer': 'https://servicewechat.com/wxc026e7662ec26a3a/42/page-frame.html'
  47. }
  48. response = requests.request("POST", url, headers=headers, data=payload)
  49. if response.json()['code'] == -10000:
  50. print(response.text)
  51. else:
  52. time_index = response.json()['content']['resp_list'][0]['indexes'][0]['time_indexes']
  53. print(time_index)
  54. if __name__ == "__main__":
  55. Weixinzhishu.weixinzhishu('weixin', 'weixinzhishu')