Skip to content

Instantly share code, notes, and snippets.

@ttpro1995
Created November 21, 2016 06:27
Show Gist options
  • Save ttpro1995/6e7fe94ea14a59a7ed4f6e62ca5098d8 to your computer and use it in GitHub Desktop.
Save ttpro1995/6e7fe94ea14a59a7ed4f6e62ca5098d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
'''
Here's how you upload an image. For this example, put the cutest picture
of a kitten you can find in this script's folder and name it 'Kitten.jpg'
For more details about images and the API see here:
https://api.imgur.com/endpoints/image
'''
# Pull authentication from the auth example (see auth.py)
import sys
from datetime import datetime
from imgurpython import ImgurClient
album = None # You can also enter an album ID here
image_path = sys.argv[1]
def upload_kitten(client):
'''
Upload a picture of a kitten. We don't ship one, so get creative!
'''
# Here's the metadata for the upload. All of these are optional, including
# this config dict itself.
config = {
'album': album,
'name': sys.argv[1],
'title': sys.argv[1],
'description': 'Keep calm and meow on on {0}'.format(datetime.now())
}
print("Uploading image... ")
image = client.upload_from_path(image_path, config=config, anon=False)
print("Done")
print()
return image
# If you want to run this as a standalone script
if __name__ == "__main__":
client_id = '68258b8f39b2879'
client_secret = '0b2690cd3a3ca99dbdc93fbd00df4e82271ece6b'
client = ImgurClient(client_id, client_secret)
image = upload_kitten(client)
print("Image was posted")
print("You can find it here: {0}".format(image['link']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment