Skip to content

Instantly share code, notes, and snippets.

@thinkJD
Last active August 29, 2015 14:05
Show Gist options
  • Save thinkJD/bbc3f350dc005e88d9cc to your computer and use it in GitHub Desktop.
Save thinkJD/bbc3f350dc005e88d9cc to your computer and use it in GitHub Desktop.
gifme.io automatic downloader
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <[email protected]> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Jan-Daniel Georgens
# ----------------------------------------------------------------------------
from BeautifulSoup import BeautifulSoup
import urllib2
import urllib
import os.path
import json
endpoint = 'http://users.gifme.io/u/thinkjd'
base_path = os.path.dirname(os.path.realpath(__file__))
save_path = os.path.join(base_path, 'gifs/')
soup = BeautifulSoup(urllib2.urlopen(endpoint).read())
with open(os.path.join(base_path, 'links.json'), 'r') as file:
imgs = json.load(file)
for link_raw in soup.findAll('img'):
link = link_raw.get('src')
if os.path.basename(link) in imgs:
break
imgs[os.path.basename(link)] = link
urllib.urlretrieve(link, os.path.join(save_path, os.path.join(save_path, os.path.basename(link))))
with open(os.path.join(base_path, 'links.json'), 'w') as file:
file.write(json.dumps(imgs, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment