Skip to content

Instantly share code, notes, and snippets.

@yoavram
Created December 21, 2012 23:25
Show Gist options
  • Save yoavram/4356539 to your computer and use it in GitHub Desktop.
Save yoavram/4356539 to your computer and use it in GitHub Desktop.
Submit file for conversion with Docverter using python with the requests library. Docverter API: http://www.docverter.com/api.html (see the httpie example). requests: http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests. I'm not sure it's relevant but I think this only worked after I installed httpie (https:/…
import requests
url = 'http://c.docverter.com/convert'
filename = 'curriculum-vita.md'
print 'Sending request to Docverter for file', filename
r = requests.post(url, data={'to':'pdf','from':'markdown'},files={'input_files[]':open(filename,'rb')})
if r.ok:
outname = '.'.join(filename.split('.')[:-1])
fout = open(outname, 'wb')
fout.write(r.content)
fout.close()
print 'Output written to', outname
else:
print 'Request failed:', r.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment