Skip to content

Instantly share code, notes, and snippets.

@filviu
Created June 5, 2016 20:22
Show Gist options
  • Save filviu/240a88efb94cd6b53876307faae3f0b3 to your computer and use it in GitHub Desktop.
Save filviu/240a88efb94cd6b53876307faae3f0b3 to your computer and use it in GitHub Desktop.
Python script to download imgur album together with descritpions. Quick and dirty (api, secret and album id to set in file before running)
#!/usr/bin/python
import textwrap
from urllib import urlretrieve
from progressbar import ProgressBar, Percentage, Bar
from imgurpython import ImgurClient
# API ID AND SECRET - REQUIRED
client_id = ''
client_secret = ''
client = ImgurClient(client_id, client_secret)
# Type here the album to download
items = client.get_album_images('TwY6q')
i = 1
for item in items:
fileName = item.link.split('/')[-1]
# urlretrieve(item.link, str(i).zfill(3)+"-"+fileName)
text_file = open(str(i).zfill(3)+"-"+item.id+".txt", "w")
print 'Downloading '+item.link,
if item.description:
if item.title:
text_file.write(item.title)
text_file.write("\n\n"+item.description)
else:
# text_file.write(textwrap.fill(item.description.encode('utf-8'),79))
text_file.write(item.description.encode('utf-8'))
text_file.close()
print 'DONE'
i += 1
# break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment