This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
twitter_media_tool/twitter_media_tool.py
2020-07-20 02:34:52 +00:00

32 lines
1.2 KiB
Python

#!/usr/bin/python3
from lib.setup import import_config_file
from lib.authentication import authenticate_twitter
from lib.TweetStreamer import TweetStreamer
from tweepy import Stream
def main():
"""
Initialize and run the TweetStreamer and listen for new tweets
"""
config = import_config_file()
if(config['twitter']['api_key'] and config['twitter']['api_key_secret'] and config['twitter']['access_token'] and config['twitter']['access_token_secret']):
twitter_client = authenticate_twitter(config['twitter'])
else:
print('Please fill out the necessary information for using the Twitter API.')
print('\thttps://developer.twitter.com')
exit(1)
tweet_stream_listener = TweetStreamer(twitter_client)
tweet_stream = Stream(auth=twitter_client.auth,
listener=tweet_stream_listener)
if(config['twitter']['follow_user']):
tweet_stream.filter(
follow=[twitter_client.get_user(config['twitter']['follow_user'])._json['id_str']], is_async=True)
else:
tweet_stream.filter(
follow=[twitter_client.me()._json['id_str']], is_async=True)
if(__name__ == '__main__'):
main()