Welcome! Log In Create A New Profile

Advanced

Basic python question

Posted by pagepipe 
Basic python question
May 22, 2011 12:43PM
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!
Re: Basic python question
May 22, 2011 12:48PM
# 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?
Re: Basic python question
May 23, 2011 03:55AM
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.
Sorry, only registered users may post in this forum.

Click here to login