d60 / twikit

Twitter API Scraper | Without an API key | Twitter Internal API | Free | Twitter scraper | Twitter Bot
https://twikit.readthedocs.io/en/latest/twikit.html
MIT License
1.5k stars 176 forks source link

How can I get trends in another country #243

Closed IK-O closed 1 month ago

IK-O commented 1 month ago

I live in Japan and I access to X from Japan but I want to get trend in US.

async def get_client_us():
    client = Client('en-US')
    if os.path.isfile('cookies_us.json'):
        client.load_cookies('cookies_us.json')
    else:
        await client.login(
            auth_info_1=USERNAME ,
            auth_info_2=EMAIL ,
            password=PASSWORD
        )

        client.save_cookies('cookies_us.json')

    return client

def get_trend_us():
    client = asyncio.run(get_client_us())
    trends = asyncio.run(get_trends(client))
    return trends

async def get_trends(client):
        trend = await client.get_trends('trending')
        return trend

asyncio.run(get_trend_us())

This code clearly uses "client = Client('en-US')". However the got trends are trends in Japan. How can I get trends in US?

d60 commented 1 month ago

@IK-O get_available_locationsでwoeid(地域のID)を取得して、client.get_place_trendsでトレンドを取得することができます。 例えばこんな感じです

locations = await client.get_available_locations()
trend = await client.get_place_trends(locations[0].id)
IK-O commented 1 month ago

回答ありがとうございます。 WOEID = 23424977 でUSが取得できました。

d60 commented 1 month ago

👍