En este artículo, vamos a aprender cómo podemos acceder a los viejos los tweets utilizando el módulo Getoldtweets3 en Python?
Biblioteca:
GetOldTweets3
GetOldTweets3
GetOldTweets3 es un pitón módulo que le ayudará a acceder a los viejos tweets, como la API de Twitter no permite que tengamos acceso a los tweets de más de 1 semana, pero con la ayuda de este módulo, se puede acceder a los tweets de cualquier fecha y cualquier tema y cualquier nombre de usuario.
Código:
# To create a base engine for the tweets:
GetOldTweets3.manager.TweetCriteria()
Código del nombre de usuario:
# importing the modules
import GetOldTweets3 as gt
# creating a base engine
engine=gt.manager.TweetCriteria()
# storing the tweets for the username
# setusername will set the username
# of the account holder
Tweets=engine.setUsername("Donald Trump").setMaxTweets(3)
# extract the tweeets
# we will take the last third tweet
# gt.manager.TweetManager.getTweets
# will extract the tweets
Tweets_Extracted=gt.manager.TweetManager.getTweets(Tweets)[2]
# print the tweet
print(Tweets_Extracted.text)
Salida:
We will get the last third tweet of Donald Trump
You're the best! Sorry for the late reply here.
This poor account is drowning in so much Trump bs,
things meant for me get lost.
Código class la búsqueda de consulta:
# importing the modules
import GetOldTweets3 as gt
# creating a base engine
engine=gt.manager.TweetCriteria()
# storing the tweets for the
# query or topic we want
# setthedate(year-month-day) to set
# untill(year-month-day)
Tweet=engine.setQuerySearch("Corona Virus in india").setSince("2020-04-01").setUntil("2020-06-01").setMaxTweets(2)
# Extract The Tweets
Extracted_Tweets=gt.manager.TweetManager.getTweets(Tweet)[1]
# print the tweet
print(Extracted_Tweets.text)
Salida:
Coronavirus live news: Brazil passes 500,000 Covid-19 cases
as India extends lockdown in ‘high-risk’ zones | World news
Código class el nombre de usuario delimitado con las fechas:
# importing the modules
import GetOldTweets3 as gt
# creating a base engine
engine=gt.manager.TweetCriteria()
# storing the tweets for the username
# and setting the dates
# setthedate(year-month-day) to set
# untill(year-month-day)
Tweet=engine.setUsername("narendramodi").setSince("2020-04-01").setUntil("2020-06-01").setMaxTweets(3)
# Extract The Tweets
# extract the third tweet
Extracted_Tweets=gt.manager.TweetManager.getTweets(Tweet)[2]
# print the tweeet
print(Extracted_Tweets.text)
salida:
अंतर्राष्ट्रीय योग दिवस जल्द ही आने वाला है। कोरोना संकट के दौरान लोग योग पर
और अधिक गंभीरता से ध्यान दे रहे हैं। हर जगह लोगों ने योग के साथ-साथ
आयुर्वेद को भी अपनाया है। सही मायने में योग
Community, Immunity और Unity सबके लिए अच्छा है। #MannKiBaat