Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection of replies #114

Open
koszzz opened this issue Jan 27, 2024 · 2 comments
Open

Collection of replies #114

koszzz opened this issue Jan 27, 2024 · 2 comments

Comments

@koszzz
Copy link

koszzz commented Jan 27, 2024

Hi!
When I used it, I found that the output result of the following code could not represent the hierarchical relationship of the replies. It just added each tweet to the List.

    user_id = (await api.user_by_login(username)).id
    tweets = await gather(api.user_tweets_and_replies(user_id, limit=1))
    posts = []
    for i in tweets:
        posts.append(json.loads(i.json()))
    posts = json.dumps(posts, ensure_ascii=False)

I'm not very familiar with Python, I wonder if I've made a mistake somewhere?
Looking forward to your reply.

@vladkens
Copy link
Owner

Hi, @koszzz.

Looks like X/Twitter for this method returns unordered data.

You can sort it manually, like:

import asyncio

from twscrape import API, gather


async def main():
    api = API()
    tweets = await gather(api.user_tweets_and_replies(2244994945, limit=10))
    tweets = [x.dict() for x in tweets]

    tweets = sorted(tweets, key=lambda x: x["date"])
    for tweet in tweets:
        print(tweet["date"], tweet["id"])


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

@koszzz
Copy link
Author

koszzz commented Feb 11, 2024

@vladkens Thank you for your reply, but that's not what I meant, I meant that all the replies and posts are together and I can't tell which reply is which.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants