922ad6db8b
* add yts_torrents project (#116) * add yts_torrents project * Added Python Script HacktoberFest 2019 (#128) * Added whatsapp-message Script * Update README.md * Script: Importance Checker (Updated Project List) (#132) * Add files to fork * Update README.md * Fixed ToDoBot link (#133) To Do bot link was using "-" instead of %20 Changed path to folders Removed full repo path to folders to make project robust to cloning as discussed on issue #139 on [AzureNotebooks](https://github.com/Microsoft/AzureNotebooks/issues/193). Fixed clean up photo directory name Fixed file organizer link Script: Importance Checker (Updated Project List) (#132) * Add files to fork * Update README.md Squash Squash Fixed ToDoBot link To Do bot link was using "-" instead of %20 parent 7c58b564104cdd1990492276292f04ec19009e57 author MatTerra <mateus.b.s.terra@gmail.com> 1574710004 -0300 committer MatTerra <mateus.b.s.terra@gmail.com> 1574710650 -0300 Squash Fixed ToDoBot link To Do bot link was using "-" instead of %20 Squash Changed path to folders Removed full repo path to folders to make project robust to cloning as discussed on issue #139 on [AzureNotebooks](https://github.com/Microsoft/AzureNotebooks/issues/193). Fixed ToDoBot link To Do bot link was using "-" instead of %20 Script: Importance Checker (Updated Project List) (#132) * Add files to fork * Update README.md * All changes made : Script added (#130) * Added whatsapp-message Script * Update README.md Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Revert "All changes made : Script added (#130)" (#135) This reverts commit |
||
---|---|---|
.. | ||
example.csv | ||
LICENSE | ||
main.py | ||
README.md | ||
requirements.txt | ||
setup.py | ||
Tool.py |
Tweets_Tool
Twitter Official API has limitations on how many tweets you can search for at a time and for the length of time (7 days/10 days). If I wanted to some historical tweets matching a certain criteria, I would have to either buy the Enterprise API or get GNIP, which both cost moneys.
Prerequisites
Since Python 2.x will be deprecated, this package assumes Python 3.x. Expected package dependencies are listed in the "requirements.txt" file for PIP, you need to run the following command to get dependencies: pip install -r requirements.txt
Components
Tweet: Model class to give some informations about a specific tweet.
- id (str)
- permalink (str)
- username (str)
- text (str)
- date (date)
- retweets (int)
- favorites (int)
- mentions (str)
- hashtags (str)
- geo (str)
TweetManager: A manager class to help getting tweets in Tweet's model
- getTweets: Return the list of tweets retrieved by using an instance of TwitterCriteria
- getJsonReponse: Actually obtains the tweets and returns an object that can be read
TwitterCriteria: A collection of search parameters to be used together with TweetManager
- setUsername (str): An optional specific username from a twitter account. Without "@"
- setSince (str. "yyyy-mm-dd"): A lower bound date to restrict search
- setUntil (str. "yyyy-mm-dd"): An upper bound date to restrist search
- setQuerySearch (str): A query text to be matched
- setTopTweets (bool): If True only the Top Tweets will be retrieved
- setNear(str): A reference location area from where tweets were generated
- setWithin (str): A distance radius from "near" location (e.g. 15mi)
- setMaxTweets (int): The maximum number of tweets to be retrieved. If this number is unsetted or lower than 1 all possible tweets will be retrieved.
TweetObtain: Returns a clean dataframe for analysis using TweetCriteria and TweetManager
- TweetObtain_function: Returns a clean dataframe for analysis using TweetCriteria and TweetManager
Simple examples of python usage
- Get tweets by username
tweetCriteria = Tool.TweetCriteria().setUsername('barackobama').setMaxTweets(1)
tweet = Tool.TweetManager.getTweets(tweetCriteria)[0]
tweets = pd.read_csv('tweets.csv')
print(tweets)
- Get tweets by query search
tweetCriteria = Tool.TweetCriteria().setQuerySearch('europe refugees').setSince("2015-05-01").setUntil("2015-09-30").setMaxTweets(1)
tweet = Tool.TweetManager.getTweets(tweetCriteria)[0]
tweets = pd.read_csv('tweets.csv')
print(tweets)
- Get tweets by username and bound dates
tweetCriteria = Tool.TweetCriteria().setUsername("barackobama").setSince("2015-09-10").setUntil("2015-09-12").setMaxTweets(1)
tweet = Tool.TweetManager.getTweets(tweetCriteria)[0]
tweets = pd.read_csv('tweets.csv')
print(tweets)
- Get the last 10 top tweets by username
tweetCriteria = Tool.TweetCriteria().setUsername("barackobama").setTopTweets(True).setMaxTweets(10)
# first one
tweet = Tool.TweetManager.getTweets(tweetCriteria)[0]
tweets = pd.read_csv('tweets.csv')
print(tweets)