Skip to content

Instantly share code, notes, and snippets.

@wenLiangcan
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wenLiangcan/57e8608c24b474c9c980 to your computer and use it in GitHub Desktop.
Save wenLiangcan/57e8608c24b474c9c980 to your computer and use it in GitHub Desktop.
#!/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