def reply_to_tweet(self, tweet, prefix): query = extract_query(tweet.text) if query is None: self.log("Couldn't find a query in {}".format(self._tweet_url(tweet))) return try: filename = make_video(query) except NotEnoughImages as e: self.log(str(e)) return if self._is_silent(): self.log("Silent mode is on. Would've responded to {} with {}".format( self._tweet_url(tweet), filename)) return media_id = upload_media(self.api, filename) self.post_tweet( "{} {}".format(prefix, query), reply_to=tweet, media_ids=[media_id], ) self.update_reply_threshold(tweet, prefix)
from __future__ import unicode_literals import sys import os import tweepy from utils import ( start_logging, upload_media, ) import logging log = logging.getLogger(__name__) start_logging() auth = tweepy.OAuthHandler(os.environ['TWITTER_CONSUMER_KEY'], os.environ['TWITTER_CONSUMER_SECRET']) auth.set_access_token(os.environ['TWITTER_ACCESS_TOKEN'], os.environ['TWITTER_ACCESS_TOKEN_SECRET']) api = tweepy.API(auth) media_id = upload_media(api, sys.argv[1]) log.info('media_id = %s', media_id)