Skip to content

Instantly share code, notes, and snippets.

@icyrhyme
Created October 23, 2012 11:02
Show Gist options
  • Save icyrhyme/3938183 to your computer and use it in GitHub Desktop.
Save icyrhyme/3938183 to your computer and use it in GitHub Desktop.
upload the image file specified by the commandline argument, then save the image's url in the clip board (windows only)
# -*- coding:utf-8 -*-
import json
import sys
import urllib
import base64
import os
def addToClipBoard(text):
command = 'echo ' + text.strip() + '| clip'
os.system(command)
def upload(fn):
print 'Opening image file %s' % fn
f = open(fn, 'rb')
para = {
'key': "77c69b52f7992b9996a2cf963eee4651",
'type': "base64",
'image': base64.b64encode(f.read()),
}
data = urllib.urlencode(para)
req = urllib.urlopen(url, data)
resp = json.loads(req.read())
link = resp['upload']['links']['original']
print link
addToClipBoard(link)
url = "http://api.imgur.com/2/upload.json"
if len(sys.argv) != 2:
print 'Usage: {0} filename'.format(sys.argv[0])
else:
fn = sys.argv[1]
upload(fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment