wxSpiderApi.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. from applications.decoratorApi import retryOnNone, retryOnTimeout
  7. class WeixinSpider(object):
  8. """
  9. Update account articles
  10. """
  11. @classmethod
  12. @retryOnTimeout()
  13. @retryOnNone()
  14. def search_articles(cls, title):
  15. """
  16. search articles in wx
  17. :return:
  18. """
  19. url = "http://8.217.190.241:8888/crawler/wei_xin/keyword"
  20. payload = json.dumps({
  21. "keyword": title,
  22. "cursor": "1"
  23. })
  24. headers = {
  25. 'Content-Type': 'application/json'
  26. }
  27. response = requests.request("POST", url, headers=headers, data=payload, timeout=10)
  28. return response.json()
  29. @classmethod
  30. @retryOnTimeout()
  31. @retryOnNone()
  32. def get_article_text(cls, content_link):
  33. """
  34. 获取文章
  35. :param content_link:
  36. :return:
  37. """
  38. url = "http://8.217.190.241:8888/crawler/wei_xin/detail"
  39. payload = json.dumps({
  40. "content_link": content_link,
  41. "is_count": False,
  42. "is_ad": False
  43. })
  44. headers = {
  45. 'Content-Type': 'application/json'
  46. }
  47. response = requests.request("POST", url, headers=headers, data=payload, timeout=10)
  48. return response.json()
  49. @classmethod
  50. @retryOnTimeout()
  51. @retryOnNone()
  52. def update_msg_list(cls, ghId, index):
  53. """
  54. :return:
  55. """
  56. url = 'http://8.217.190.241:8888/crawler/wei_xin/blogger'
  57. payload = {
  58. 'account_id': ghId,
  59. 'cursor': index,
  60. }
  61. headers = {
  62. 'Content-Type': 'application/json'
  63. }
  64. response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=10)
  65. return response.json()
  66. @classmethod
  67. @retryOnTimeout()
  68. @retryOnNone()
  69. def get_account_by_url(cls, content_url):
  70. """
  71. 通过文章获取账号信息
  72. :param content_url:
  73. :return:
  74. """
  75. response = requests.request(
  76. "POST",
  77. url='http://8.217.190.241:8888/crawler/wei_xin/account_info',
  78. headers={'Content-Type': 'application/json'},
  79. json={"content_link": content_url},
  80. timeout=10
  81. )
  82. return response.json()