Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Welcome everyone to contribute to this project!
- [sort_n_numbers.py](https://github.com/Henry-Jia/python-tools/blob/master/sort_n_numbers.py): a program to sort n numbers
- [table_element_statistics_and_deletion.py](https://github.com/Henry-Jia/python-tools/blob/master/table_element_statistics_and_deletion.py): excel table element statistics and deletion
- [tic_tac.py](https://github.com/Henry-Jia/python-tools/blob/master/tic_tac.py): Tic Tac Toe Game
- [twitter_seek/twitter_peek.py](https://github.com/Henry-Jia/python-tools/blob/master/twitter_peek/twitter_peek.py): A twitter peek to get last n tweets in a twitter page.
- [webcrawler.py](https://github.com/Henry-Jia/python-tools/blob/master/webcrawler.py): this is a website crawler written by using selenium framework for automation
- [wechat_friends_analyse](https://github.com/Henry-Jia/python-tools/tree/master/wechat_friends_analyse): WeChat friends statistics and analysis tools

Expand Down
1 change: 1 addition & 0 deletions twitter_peek/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tweepy==3.8.0
31 changes: 31 additions & 0 deletions twitter_peek/twitter_peek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
""" A Twitter Listener to seek tweets from specific users """

from pprint import pprint
from tweepy import OAuthHandler
from tweepy import API
from tweepy import Cursor

# All those keys could ge obtained though your twitter account
consumer_key = "YOUR_CONSUMER_TWITTER_KEY"
consumer_secret = "YOUR_CONSUMER_SECRET_TWITTER_KEY"
access_token = "TWITTER_ACCESS_TOKEN"
access_token_secret = "TWITTER_ACCESS_SECRET_TOKEN"


class TwitterPeeker:
def __init__(self):
self.auth = OAuthHandler(consumer_key, consumer_secret)
self.auth.set_access_token(access_token, access_token_secret)
self.auth_api = API(self.auth)

def get_first_n_tweets(self, target_account, tweet_quantity):
tweets = []
for status in Cursor(self.auth_api.user_timeline, id=target_account).items(tweet_quantity):
tweets.append(status.text)
return tweets

if __name__ == "__main__":
target_account = 'TheGentlebros'
tweet_quantity = 10
twitter_peeker = TwitterPeeker()
pprint(twitter_peeker.get_first_n_tweets(target_account, tweet_quantity), indent=4)