Skip to content

Instantly share code, notes, and snippets.

@wenLiangcan wenLiangcan/drp.py
Last active Aug 29, 2015

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.