Created
January 20, 2018 18:04
-
-
Save ellieayla/4322b5da79b74bb09f96193c1dc01cb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# I had a pile of http://fav.me/... urls in a text file, and wanted to retrieve the original files via OEMBED. | |
from urllib.parse import quote | |
from urllib.request import urlopen, urlretrieve | |
import json | |
import sys | |
if __name__ == "__main__": | |
for fav in sys.stdin: | |
url = fav.split(' ')[0] | |
print(url) | |
with urlopen("https://backend.deviantart.com/oembed?url=" + quote(url)) as response: | |
r = json.load(response) | |
basename = r['url'].split("/")[-1] | |
local_filename, headers = urlretrieve(r['url'], basename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment