Advertisement
thinkJD

Untitled

Jul 29th, 2014
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. # ----------------------------------------------------------------------------
  2. # "THE BEER-WARE LICENSE" (Revision 42):
  3. # <jd.georgens@gmail.com> wrote this file. As long as you retain this notice you
  4. # can do whatever you want with this stuff. If we meet some day, and you think
  5. # this stuff is worth it, you can buy me a beer in return Jan-Daniel Georgens
  6. # ----------------------------------------------------------------------------
  7.  
  8. from BeautifulSoup import BeautifulSoup
  9. import urllib2
  10. import urllib
  11. import os.path
  12. import json
  13.  
  14. endpoint = 'http://users.gifme.io/u/thinkjd'
  15. base_path = os.path.dirname(os.path.realpath(__file__))
  16. save_path = os.path.join(base_path, 'gifs/')
  17. soup = BeautifulSoup(urllib2.urlopen(endpoint).read())
  18.  
  19. with open(os.path.join(base_path, 'links.json'), 'r') as file:
  20.     imgs = json.load(file)
  21.  
  22. for link_raw in soup.findAll('img'):
  23.     link = link_raw.get('src')
  24.     if os.path.basename(link) in imgs:
  25.         break
  26.     imgs[os.path.basename(link)] = link
  27.     urllib.urlretrieve(link, os.path.join(save_path, os.path.join(save_path, os.path.basename(link))))
  28.  
  29. with open(os.path.join(base_path, 'links.json'), 'w') as file:
  30.     file.write(json.dumps(imgs, indent=4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement