def get(self, twitter_handle): try: t = twi.twitter_api("keys") #get twitter keys from keys file except: s = stubs.stubFuncs( ) #create an object for stubs, these will run if no keys are available resp = s.noKeys() return resp f = ff.ffmpeg_api() #create an ffmpeg object handles = queue.Queue( ) #create queue to hold twitter handles in the order the handle called the api tweets = queue.Queue( ) #create queue to hold tweets in the order they were tweeted by each handle handles.put(twitter_handle) #add twitter handle to queue profilePic = t.get_profilePic( twitter_handle) #get the users profile picture profileTweets = t.get_tweets(twitter_handle) #get the users tweets #thread to add tweets to tweets queue to create images in chronological order of the tweets t = threading.Thread(name="producer", target=addTweets, args=(tweets, twitter_handle, profilePic, profileTweets)) t.start() #thread to convert tweets to images t = threading.Thread(name="imageConverter", target=tweetsToPics, args=(tweets, f)) t.start() #thread to convert the images to a video t = threading.Thread(name="videoCreator", target=videoProcessor, args=(handles, f)) t.start() resp = { "file location": os.getcwd() + '/' + twitter_handle + '_' + r'twitter_feed.mp4' } #create json response for api call return resp
def last_tweet(self, channel, nick, msg, args): if 'twitter_api' not in self.bot.plugin_config: logging.debug('configure twitter plugin') self.bot.msg(channel, 'Twitter plugin not configured') return False creds = self.bot.plugin_config['twitter_api'] auth = twitter_oauth(creds['access_token'], creds['access_token_secret'], creds['consumer_key'], creds['consumer_secret']) t = twitter_api(auth=auth) try: user = t.users.lookup(screen_name=args['user'])[0] except TwitterHTTPError: logging.exception('Caught twitter api exception:') self.bot.msg('Error retreiving tweet from %s' % args['user']) return text = user['status']['text'].encode('UTF-8') screen_name = args['user'].encode('UTF-8') formatted_msg = assembleFormattedText(A.bold[screen_name]) formatted_msg += assembleFormattedText(A.normal[" tweets: "]) + text self.bot.msg(channel, formatted_msg)
from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener from twitter import get_auth, twitter_api api = twitter_api() keyword_list = [ 'python', 'javascript', 'php', 'C#', ] #Track list limit = 200 class MyStreamListener(StreamListener): def __init__(self): super(MyStreamListener, self).__init__() self.num_tweets = 0 def on_data(self, data): if self.num_tweets < limit: self.num_tweets += 1 try: with open('tweet_mining.json', 'a') as tweet_file: tweet_file.write(data) return True except BaseException as e: print("Failed on_data: %s" % str(e))
import twitter import reddit from formatting import format_tweets from config import load_config # Initalization config = load_config() twitter_api = twitter.twitter_api(config["twitter"]) reddit_api = reddit.reddit_api(config["reddit"]) most_recent_id = twitter.last_tweet_id(twitter_api, config["twitter"]) def handler(event, context): global most_recent_id # In case of test, only get the lat tweet and display it, but don't submit if "test" in event: most_recent_id -= 1 # Get new tweets and update id of the most recent tweet new_tweets, most_recent_id = twitter.last_tweets(twitter_api, config["twitter"], since=most_recent_id) if new_tweets: # Format title and URL for reddit titles_urls = format_tweets(new_tweets, config["format"]) # Submit them on reddit, reversed to submit most recent one last permalinks = ["None"] * len(new_tweets) if "test" not in event: permalinks = reddit.submit(reddit_api, config["reddit"],