123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- """
- @author: luojunhui
- """
- import json
- import requests
- class ArticleManager(object):
- """
- Update account articles
- """
- @classmethod
- def search_articles(cls, title):
- """
- search articles in wx
- :return:
- """
- url = "http://8.217.190.241:8888/crawler/wei_xin/keyword"
- payload = json.dumps({
- "keyword": title,
- "cursor": "1"
- })
- headers = {
- 'Content-Type': 'application/json'
- }
- response = requests.request("POST", url, headers=headers, data=payload)
- return response.json()
- @classmethod
- def get_article_text(cls, content_link):
- """
- 获取文章
- :param content_link:
- :return:
- """
- url = "http://8.217.190.241:8888/crawler/wei_xin/detail"
- payload = json.dumps({
- "content_link": content_link,
- "is_count": False,
- "is_ad": False
- })
- headers = {
- 'Content-Type': 'application/json'
- }
- response = requests.request("POST", url, headers=headers, data=payload)
- return response.json()
- @classmethod
- def getAccountArticleList(cls, gh_id, cursor):
- """
- 获取账号的文章list
- :return:
- """
- url = 'http://8.217.190.241:8888/crawler/wei_xin/blogger'
- payload = {
- 'account_id': gh_id,
- 'cursor': cursor,
- }
- msg_list = []
- next_cursor = None
- has_more = None
- try:
- res_data = requests.request("POST", url, headers={}, data=json.dumps(payload)).json()['data']
- msg_list = res_data['data']
- next_cursor = res_data['next_cursor']
- has_more = res_data['has_more']
- print(json.dumps(res_data, ensure_ascii=False, indent=4))
- # for msg in msg_list:
- # msg['cursor'] = curso
- # msg['next_cursor'] = next_cursor
- # msg['has_more'] = has_more
- except Exception as e:
- print(e)
- return msg_list, next_cursor, has_more
- if __name__ == '__main__':
- AM = ArticleManager()
- AM.getAccountArticleList(gh_id="gh_5ae65db96cb7", cursor=None)
|