Created
May 7, 2013 12:31
-
-
Save zhwei/5532211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = "zhwei" | |
# 使用imgur的api上传图片并返回url | |
import urllib2 | |
import urllib | |
import json | |
def uploadgeturl(pic): | |
url = "https://api.imgur.com/3/image" | |
header = {"Authorization":"Client-ID 58c6c1449861345"} | |
datas={"image":pic} | |
datas = urllib.urlencode(datas) | |
req = urllib2.Request(url,data=datas,headers=header) | |
json_object = urllib2.urlopen(req).read() | |
result = json.loads(json_object)['data']['link'] | |
return result | |
# 测试 | |
#test = file("test.jpg").read() | |
#print uploadgeturl(test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add this
and move code to /usr/bin/