I am trying to store a list of objects using Tweepy's statuses_lookup api call. Each call to statuses_lookup takes in a list of IDs, and can contain up to 100 IDs.
This function below takes in a list of IDs, and I am trying to append all the metadata returned from the API call into the tweetData list.
def lookupTweets(self, tweetIds): tweetData = [] i = 0 while i < len(tweetIds): print(i) if len(tweetIds) - i > 0: statuses = self.status_lookup(tweetIds[i + 99]) else: statuses = self.status_lookup(tweetIds[i, len(tweetIds) - i]) tweetData.append(statuses) i += 100 return tweetData And here is the async function that makes the api call
async def status_lookup(self, tweets): return self.api.statuses_lookup(tweets) And here is the main method:
if __name__ == "__main__": twitterEngine = TwitterEngine() tweets = twitterEngine.ingestData("democratic-candidate-timelines.txt") twitterData = twitterEngine.lookupTweets(tweets) loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait(twitterData)) print(twitterData) When I print the result of twitterData, I get a list of coroutine objects. The output looks something like this: [<coroutine object TwitterEngine.status_lookup at 0x105bd16d0>]. However, I want the actual metadata and not the coroutine object.
I'm new to async programming in Python, and any guidance would be greatly appreciated!