0

I'm having trouble with my code here when searching for popular or trending subreddits


# Set up Reddit API credentials
client_id = reddit_client_id
client_secret = reddit_client_secret
user_agent = reddit_client_user_agent

#scrape reddit subreddits
async def scrape_subreddit(subreddit_name, limit):
    async with asyncpraw.AsyncReddit(
        client_id=client_id,
        client_secret=client_secret,
        user_agent=user_agent,
    ) as reddit:
        subreddit = await reddit.subreddit(subreddit_name)
        async for submission in subreddit.new(limit=limit):
            yield {
                "title": submission.title,
                "score": submission.score,
                "num_comments": submission.num_comments,
                "url": submission.url,
            }
#get subreddits
subreddit_names = ["Philippines", "PhilippinesMemes"]
limit = 100

loop = asyncio.get_event_loop()
tasks = [scrape_subreddit(subreddit_name, limit) for subreddit_name in subreddit_names]
results = loop.run_until_complete(asyncio.gather(*tasks))

post_data = []
for result in results:
    post_data.extend(result)

#analyzing scraped data
popular_discussions = sorted(post_data, key=lambda x: x["score"], reverse=True)

trending_topics = sorted(post_data, key=lambda x: x["num_comments"], reverse=True)

keyword = "COVID-19"  # Example keyword
keyword_posts = [post for post in post_data if keyword in post["title"]]

upon running the results line, the error appears TypeError: An asyncio.Future, a coroutine or an awaitable is required

Code is currently running on Google Colab which is why I need to use asyncpraw instead of the regular praw package

0 Answers0