Skip to content

Instantly share code, notes, and snippets.


zph/twitter-gif Secret

Created Mar 8, 2017
What would you like to do?
#!/usr/bin/env python
import sys
import os
import re
import logging
import cloudconvert
import requests
usage = "python {} tweet_link_with_gif [outputfilename]".format(sys.argv[0])
logger = logging.getLogger(__name__)
if len(sys.argv) < 2:
twitter_page = sys.argv[1]
output = sys.argv[2]"Checking Twitter Page: {}".format(twitter_page))
home = os.getenv("HOME")
req = requests.get(twitter_page)
link_matcher = re.compile("*).jpg")
matches =
img_id =
with open("{}/.config/cloudconvert".format(home)) as f:
token =
api = cloudconvert.Api(token)
link = "{}.mp4".format(img_id)"Found MP4 Link: {}".format(link))
process = api.convert({
"inputformat": "mp4",
"outputformat": "gif",
"input": "download",
"file": link
process.wait() # wait until conversion finished
filename = link.split("/")[-1].split(".")[0]
if output == "":
output = filename + ".gif""{}".format(output))"Saved gif to {}".format(output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment