Skip to content

Instantly share code, notes, and snippets.

@iambibhas
Last active August 10, 2020 10:09
Show Gist options
  • Save iambibhas/6855102 to your computer and use it in GitHub Desktop.
Save iambibhas/6855102 to your computer and use it in GitHub Desktop.
Python script to upload image to imgur from linux terminal. Must have the `sh` package installed.

This uses sh package. Install it using pip.

$ (sudo )pip install sh

Then place this script with the name imgur in some location that's in your PATH, chmod +x the file and upload like this

$ imgur ~/Pictures/Screenshot\ from\ 2013-10-06\ 20:01:32.png
#! /usr/bin/env python
from sh import curl # install `sh` with `pip install sh`
import json
import sys
try:
resp = curl(
"https://api.imgur.com/3/image",
H="Authorization: Client-ID 0b1eeceb9d77e1", # Get your client ID from imgur.com
X="POST",
F='image=@%s' % sys.argv[1]
)
objresp = json.loads(resp.stdout)
if objresp.get('success', False):
print objresp['data']['link']
else:
print 'Error: ', objresp['data']['error']
except Exception as e:
print 'Error: ', e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment