updateAccountArticles.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. class ArticleManager(object):
  7. """
  8. Update account articles
  9. """
  10. @classmethod
  11. def search_articles(cls, title):
  12. """
  13. search articles in wx
  14. :return:
  15. """
  16. url = "http://8.217.190.241:8888/crawler/wei_xin/keyword"
  17. payload = json.dumps({
  18. "keyword": title,
  19. "cursor": "1"
  20. })
  21. headers = {
  22. 'Content-Type': 'application/json'
  23. }
  24. response = requests.request("POST", url, headers=headers, data=payload)
  25. return response.json()
  26. @classmethod
  27. def get_article_text(cls, content_link):
  28. """
  29. 获取文章
  30. :param content_link:
  31. :return:
  32. """
  33. url = "http://8.217.190.241:8888/crawler/wei_xin/detail"
  34. payload = json.dumps({
  35. "content_link": content_link,
  36. "is_count": False,
  37. "is_ad": False
  38. })
  39. headers = {
  40. 'Content-Type': 'application/json'
  41. }
  42. response = requests.request("POST", url, headers=headers, data=payload)
  43. return response.json()
  44. @classmethod
  45. def getAccountArticleList(cls, gh_id, cursor):
  46. """
  47. 获取账号的文章list
  48. :return:
  49. """
  50. url = 'http://8.217.190.241:8888/crawler/wei_xin/blogger'
  51. payload = {
  52. 'account_id': gh_id,
  53. 'cursor': cursor,
  54. }
  55. msg_list = []
  56. next_cursor = None
  57. has_more = None
  58. try:
  59. res_data = requests.request("POST", url, headers={}, data=json.dumps(payload)).json()['data']
  60. msg_list = res_data['data']
  61. next_cursor = res_data['next_cursor']
  62. has_more = res_data['has_more']
  63. print(json.dumps(res_data, ensure_ascii=False, indent=4))
  64. # for msg in msg_list:
  65. # msg['cursor'] = curso
  66. # msg['next_cursor'] = next_cursor
  67. # msg['has_more'] = has_more
  68. except Exception as e:
  69. print(e)
  70. return msg_list, next_cursor, has_more
  71. if __name__ == '__main__':
  72. AM = ArticleManager()
  73. AM.getAccountArticleList(gh_id="gh_5ae65db96cb7", cursor=None)