Last active
August 29, 2015 14:06
-
-
Save wenLiangcan/57e8608c24b474c9c980 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
""" | |
Upload image to http://drp.io in terminal. | |
""" | |
from __future__ import print_function | |
import sys | |
import requests | |
domain = 'http://drp.io/{}' | |
api = 'http://api.drp.io/{}' | |
upload = 'upload' | |
photo = 'photo/{}' | |
files = 'files/{}' | |
FAKE_UA = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) \ | |
AppleWebKit/537.36 (KHTML, like Gecko) \ | |
Chrome/30.0.1599.114 Safari/537.36" | |
} | |
def upload_image(path): | |
with open(path, 'rb') as image: | |
imgdata = {'file': image} | |
rsp = requests.post(api.format(upload), headers=FAKE_UA, files=imgdata) | |
xid = rsp.json()['xid'] | |
photo_info = requests.get( | |
api.format(photo.format(xid)), headers=FAKE_UA).json() | |
return api.format(files.format(photo_info['file'])) | |
if __name__ == '__main__': | |
print(upload_image(sys.argv[1]), file=sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment