Closed carlosdcuba1 closed 9 months ago
Hi, @carlosdcuba1. Can you provide example how you exactly run this lines:
try:
async with aclosing(api.search(query, limit=limit_tweets)) as gen:
async for tweet in gen:
if tweet.id < 123:
break
except Exception as err:
print('ERROR downloading')
All asyncio code should be run by asyncio.run
`import asyncio from twscrape import AccountsPool, API from contextlib import aclosing
class TwScrap:
async def get_user_timeline_test(self, user_id, last_tweet=0):
pool = AccountsPool()
api = API(pool)
list_tweets = []
limit_tweets = -1 if last_tweet != 0 else 50
more_tweets = -1 if last_tweet == 0 else 50
try:
async with aclosing(api.user_tweets_and_replies(user_id, limit=limit_tweets)) as gen:
async for tweet in gen:
if tweet.user.id == user_id:
list_tweets.append(tweet)
if tweet.id < last_tweet:
more_tweets -= 1
if more_tweets <= 0 and limit_tweets == -1:
break
except Exception as err:
print('ERROR downloading data for user:', user_id, err, flush=True)
return list_tweets
user=44196397 #elon musk tws=TwScrap() tweets=asyncio.run(tws.get_user_timeline_test(user, 1676784259359490048)) print(tweets) exit() `
Thanks for all
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
Hi, I got this error when I try to break a for iteration:
Here is my code:
Thanks for all.