Creating a gmail wordcloud

Standard

I have created a python program that generates a wordcloud based on your gmail account. The output may look something like this depending on the contents of your emails:

gmail

First you will need a small script that interacts with the gmail service. We have created a small script that interact with gmail. It relies on gmaillib installed and you will need to set: allow “less-secure” applications to access gmail server:  https://www.google.com/settings/security/lesssecureapps

Gmail example:

If this script runs successfully you have almost all requirements installed. You will also need the library called wordcloud. We rebuild the system such that we get one long string containing the message bodies, which we feed as input to the wordcloud instance. The variable amount contains the number of mails to fetch. We have set it to 100 but you could set it to all messages using  get_inbox_count() or you could simply fetch all emails of the last week.

Final program:

Web

Requests: HTTP for Humans

Standard

If you want to request data from webservers, the traditional way to do that in Python is using the urllib library. While this library is effective, you could easily create more complexity than needed when building something. Is there another way?

Requests is an Apache2 Licensed HTTP library, written in Python. It’s powered by httplib and urllib3, but it does all the hard work and crazy hacks for you.

To install type:

The Requests library is now installed. We will list some examples below:

Grabbing raw html using HTTP/HTTPS requests
We can now query a website as :

Save it and run with:

It will output the raw HTML code.

Download binary image using Python

python

An image retrieved using python

Website status code (is the website online?)

This returns 200 (OK). A list of status codes can be found here: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Retrieve JSON from a webserver 
You can easily grab a JSON object from a webserver.

HTTP Post requests using Python

SSL verification, verify certificates using Python