Created
December 21, 2012 23:25
-
-
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:/…
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
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