search.py 788 B

123456789101112131415161718192021222324252627
  1. from app.infra.shared import AsyncHttpClient
  2. async def search_in_toutiao(keyword):
  3. url = "http://crawler-cn.aiddit.com/crawler/tou_tiao_hao/keyword"
  4. data = {
  5. "keyword": keyword,
  6. }
  7. headers = {
  8. "Content-Type": "application/json",
  9. }
  10. async with AsyncHttpClient(timeout=120) as client:
  11. response = await client.post(url, json=data, headers=headers)
  12. return response
  13. async def get_toutiao_detail(link):
  14. url = "http://crawler-cn.aiddit.com/crawler/tou_tiao_hao/detail"
  15. data = {
  16. "content_link": link,
  17. }
  18. headers = {
  19. "Content-Type": "application/json",
  20. }
  21. async with AsyncHttpClient(timeout=120) as client:
  22. response = await client.post(url, json=data, headers=headers)
  23. return response