From d3ac7c48bc14b816b4e6ef72deeab30d56f9ff41 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Wed, 5 Aug 2020 15:51:27 -0400 Subject: [PATCH] turn into working cli tool --- README.md | 3 +++ async-upload.py | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1a43541..1e3c035 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +Original repo: https://github.com/twitterdev/large-video-upload-python +Changes here are meant to be rebased. + # Large Media Upload This Python sample demonstrates the following process of uploading large media (video / GIF / image) files asynchronously with the Twitter API, via the "chunked upload" method. diff --git a/async-upload.py b/async-upload.py index 4c37c02..2028355 100644 --- a/async-upload.py +++ b/async-upload.py @@ -10,13 +10,12 @@ from requests_oauthlib import OAuth1 MEDIA_ENDPOINT_URL = 'https://upload.twitter.com/1.1/media/upload.json' POST_TWEET_URL = 'https://api.twitter.com/1.1/statuses/update.json' -CONSUMER_KEY = 'your-consumer-key' -CONSUMER_SECRET = 'your-consumer-secret' -ACCESS_TOKEN = 'your-access-token' -ACCESS_TOKEN_SECRET = 'your-access-secret' - -VIDEO_FILENAME = 'path/to/video/file' +CONSUMER_KEY = 'hJHyPhuU7nSVHrKTVsGVDM4Lw' +CONSUMER_SECRET = '8UCYePqc1y9DY6mg0yQzLoTuq57AIysype2Si63714uACGMCbO' +with open(os.path.expanduser('~') + '/.rainbow_oauth-fsf') as fp: + ACCESS_TOKEN = fp.readline().rstrip('\n') + ACCESS_TOKEN_SECRET = fp.readline().rstrip('\n') oauth = OAuth1(CONSUMER_KEY, client_secret=CONSUMER_SECRET, @@ -153,7 +152,7 @@ class VideoTweet(object): Publishes Tweet with attached video ''' request_data = { - 'status': 'I just uploaded a video with the @TwitterAPI.', + 'status': tweet_text, 'media_ids': self.media_id } @@ -162,6 +161,13 @@ class VideoTweet(object): if __name__ == '__main__': + if (len(sys.argv) < 2): + print('error: expected 2+ arguments, path to video (no spaces) and tweet text') + sys.exit(1) + VIDEO_FILENAME = sys.argv[1] + global tweet_text + tweet_text = ' '.join(sys.argv[2:]) + videoTweet = VideoTweet(VIDEO_FILENAME) videoTweet.upload_init() videoTweet.upload_append() -- 2.25.1