diff --git a/README.md b/README.md index 2fcd568..ca7ba2f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/twitter_peek/requirements.txt b/twitter_peek/requirements.txt new file mode 100644 index 0000000..c047018 --- /dev/null +++ b/twitter_peek/requirements.txt @@ -0,0 +1 @@ +tweepy==3.8.0 diff --git a/twitter_peek/twitter_peek.py b/twitter_peek/twitter_peek.py new file mode 100644 index 0000000..eb5726e --- /dev/null +++ b/twitter_peek/twitter_peek.py @@ -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)