Skip to content

Instantly share code, notes, and snippets.

@jkeyes
Created August 21, 2013 21:00
Show Gist options
  • Save jkeyes/6300216 to your computer and use it in GitHub Desktop.
Save jkeyes/6300216 to your computer and use it in GitHub Desktop.
Docraptor async example
import time
from docraptor import DocRaptor
docraptor = DocRaptor()
print "Create PDF"
# resp = docraptor.create({
# 'document_content': '<h1>python-docraptor</h1><p>Async Test</p>',
# 'test': True,
# 'async': True
# })
resp = docraptor.create({
'document_content': "<html><p>test</p></html>",
'test': True,
'async': True,
'name': "test doc",
'javascript': True
})
print "Status ID: %s" % (resp['status_id'])
status_id = resp['status_id']
resp = docraptor.status(status_id)
print " %s" % (resp['status'])
while resp['status'] != 'completed':
time.sleep(3)
resp = docraptor.status(status_id)
print " %s" % (resp['status'])
print "Download to test_async.pdf",
with open("test_async.pdf", "wb") as f:
f.write(docraptor.download(resp['download_key']).content)
print "[DONE]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment