Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ----------------------------------------------------------------------------
- # "THE BEER-WARE LICENSE" (Revision 42):
- # <jd.georgens@gmail.com> 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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement