Skip to content

Instantly share code, notes, and snippets.

@filviu
Last active May 20, 2016 08:26
Show Gist options
  • Save filviu/002b7aff172caa735e059b0e63410fba to your computer and use it in GitHub Desktop.
Save filviu/002b7aff172caa735e059b0e63410fba to your computer and use it in GitHub Desktop.
Download from imgur using api and saving descriptions together with pictures. Downloads in current folder. You need to register for a client id and secret
#!/usr/bin/python
import textwrap
from urllib import urlretrieve
from progressbar import ProgressBar, Percentage, Bar
from imgurpython import ImgurClient
client_id = '1c707373dd86e34'
client_secret = 'b490569a3a9edb48ee2c25149a272931b41bf6f0'
client = ImgurClient(client_id, client_secret)
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'
# break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment