This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Basic python question

pagepipe wrote on 2011-05-22:
Hello I am a high school student and I just learned python yesterday.
I am writing a program to help people living in the countries with internet censorship to bypass it, by getting requests via email, and automatically download the URL as a .pdf flie and send it back to them so they can read it without connecting to the actual website.
So i am trying out your API. I don't know how to save the URL as a pdf file.

client.convertURI('http://www.google.com/',"document.pdf")

this obviously doesn't work.

So how can I save a URL to a PDF file?

Also, if I purchase a lot of tokens at once, will they expire after a moth?

And since I am still in the testing phrase, and messed up a lot, can you give me a little bit more for testing purposes? thank you!
pagepipe wrote on 2011-05-22:
# convert a web page and store the generated PDF into a pdf variable
pdf = client.convertURI('http://example.com')

what should i do with the pdf variable to save it into a local PDF file?
support wrote on 2011-05-23:
Hi,

You can store the generated pdf to a variable and then save it to a file:
pdf = client.convertURI('http://example.com')
open('document.pdf', 'wb').write(pdf)

Or you can save the pdf directly to a file:
client.convertURI('http://example.com', open('document.pdf', 'wb'))


The latter one is more efficient and should be preferred. The convertURI() method is documented here.

If you run out of tokens provided for the trial period and need more for testing just let us know.

As for purchasing the tokens, a plan provides your account with a respective number of tokens per month. Unused tokens are not carried over to the next month.