Convert HTML to PDF Like a Boss Using DocRaptor

DocRaptor is an awesome package which allows you to convert your HTML document to PDF. It works with Python 2 and Python 3.

Here are some features of DocRaptor:

  1. Support any size document, with simple, per-document pricing.
  2. Supports layout and sizing changes on a per-page basis
  3. Asynchronous document generation, for long or large documents.
  4. 99.99% uptime guarantee

Installing DocRaptor

To intall DocRaptor using pip type the following command:

You can also use easy_intall:

Creating PDFs

Creating PDF from you HTML docment is quite simple just post your HTML to DocRaptor and you will get the response as text/plain.

Run the script and it will create a pdf file named output.pdf.

The preceding code generates PDF synchronously. Here is how you can generate PDFs asynchronously:

Live Coding

Last week I stumbled upon – a website that teaches students coding live. Here is how it works: Developers stream live video and users can ask questions and provide feedback.

You can teach yourself almost anything. Currently, the site has tutorials about Python, Java, Ruby, C, C++, C#, WordPress etc. etc.

Using a free account you can view live videos and chat with members. If you want more support or want to create your own private channel then you can sign up for a pro account which cost around $10/m. Overall the site is excellent not only for beginners but for skilled professionals who want to sharpen their skills. So what are you waiting for ? Go ahead sign up and start streaming.

Fetching records using fetchone() and fetchmany()

Up until now we have been using fetchall()  method of cursor object to fetch the records. This process of accessing all records in one go is not every efficient. As a result MySQLdb has fetchone() and fetchmany() methods of cursor object to fetch records more efficiently.

Method Description
fetchone() This method returns one record as a tuple, If there are no more records then it returns None
fetchmany(number_of_records) This method accepts number of records to fetch and returns tuple where each records itself is a tuple. If there are not more records then it returns an empty tuple.
Continue reading

MySQLdb Fetching results

In the previous post we have seen how to execute sql queries using execute()  method. execute()  method returns affected rows, it doesn’t return the result. To fetch result we use the fetchall()  method of the cursor object

Syntax: cursor.fetchall()

On success it returns tuple of rows where each row is a tuple. Continue reading

Python String Formatting

format() method allows you format string in any way you want.

Syntax: template.format(p1, p1, .... , k1=v1, k2=v2)

template is a string containing format codes, format()  method uses it’s argument to substitute value for each format codes. For e.g

{0}  and {1}  are format codes. The format code {0}  is replaced by the first argument of format()  i.e 12 , while {1}  is replaced by the second argument of format()  i.e 31 . Continue reading