"""Example: Threads-Web-API

SDK attribute: ``client.threads_web``
Endpoints: 11

Usage::

    python examples/threads_web.py

AUTO-GENERATED by scripts/generate_examples.py.
"""

import asyncio
import json

from tikhub import AsyncTikHub

API_KEY = "YOUR_API_KEY"


async def main():
    async with AsyncTikHub(api_key=API_KEY) as client:

        # GET /api/v1/threads/web/fetch_user_info
        # 获取用户信息/Get user info
        result = await client.threads_web.fetch_user_info(username='lilbieber')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/fetch_user_info_by_id
        # 根据用户ID获取用户信息/Get user info by ID
        result = await client.threads_web.fetch_user_info_by_id(user_id='67027868801')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/fetch_user_posts
        # 获取用户帖子列表/Get user posts
        result = await client.threads_web.fetch_user_posts(user_id='63625256886')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/fetch_user_reposts
        # 获取用户转发列表/Get user reposts
        result = await client.threads_web.fetch_user_reposts(user_id='63625256886')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/fetch_user_replies
        # 获取用户回复列表/Get user replies
        result = await client.threads_web.fetch_user_replies(user_id='63625256886')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/fetch_post_detail
        # 获取帖子详情/Get post detail
        result = await client.threads_web.fetch_post_detail(post_id='3349029093483693129')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/fetch_post_detail_v2
        # 获取帖子详情 V2(支持链接)/Get post detail V2(supports URL)
        result = await client.threads_web.fetch_post_detail_v2(post_id='DPVUglOjOUu', url='https://www.threads.com/@taylorswift/post/DPVUglOjOUu')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/fetch_post_comments
        # 获取帖子评论/Get post comments
        result = await client.threads_web.fetch_post_comments(post_id='3390920896561588969')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/search_top
        # 搜索热门内容/Search top content
        result = await client.threads_web.search_top(query='bitcoin')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/search_recent
        # 搜索最新内容/Search recent content
        result = await client.threads_web.search_recent(query='bitcoin')
        print(json.dumps(result, indent=2, ensure_ascii=False))

        # GET /api/v1/threads/web/search_profiles
        # 搜索用户档案/Search profiles
        result = await client.threads_web.search_profiles(query='mark')
        print(json.dumps(result, indent=2, ensure_ascii=False))


if __name__ == "__main__":
    asyncio.run(main())