<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python &#187; Web</title>
	<atom:link href="/python/category/web/feed/" rel="self" type="application/rss+xml" />
	<link>https://talkera.org/python</link>
	<description>Programming Blog</description>
	<lastBuildDate>Sun, 01 Feb 2015 17:15:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1</generator>
	<item>
		<title>Creating a gmail wordcloud</title>
		<link>https://talkera.org/python/creating-a-gmail-wordcloud/</link>
		<comments>https://talkera.org/python/creating-a-gmail-wordcloud/#comments</comments>
		<pubDate>Sun, 11 Jan 2015 20:19:42 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[gmail]]></category>

		<guid isPermaLink="false">https://talkera.org/python/?p=28</guid>
		<description><![CDATA[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: 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 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I have created a python program that <strong>generates a wordcloud based on your gmail</strong> account. The output may look something like this depending on the contents of your emails:</p>
<p><a href="/python/wp-content/uploads/2015/01/gmail2.jpg"><img class="size-medium wp-image-33" src="/python/wp-content/uploads/2015/01/gmail2-300x150.jpg" alt="gmail" width="300" height="150" /></a></p>
<p>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 <a href="https://github.com/thedjpetersen/gmaillib" target="_blank">gmaillib</a> installed and you will need to set: allow &#8220;less-secure&#8221; applications to access gmail server:  <a href="https://www.google.com/settings/security/lesssecureapps" target="_blank">https://www.google.com/settings/security/lesssecureapps</a></p>
<p><strong>Gmail example:</strong></p><pre class="crayon-plain-tag">#!/usr/bin/env python
import gmaillib
from collections import Counter


def getMails(cnt,account, start,amount):
  emails = account.inbox(start, amount)

  for email in emails:
    cnt[email.sender_addr] += 1

amountOfMails = 100
cnt = Counter()
username = raw_input("Gmail account: ")
password = raw_input("Password: ")

account = gmaillib.account(username, password)

getMails(cnt,account,0,amountOfMails)
print cnt</pre><p>If this script runs successfully you have almost all requirements installed. You will also need the library called <a href="https://github.com/amueller/word_cloud" target="_blank">wordcloud</a>. 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.</p>
<p><strong>Final program:</strong></p><pre class="crayon-plain-tag">#!/usr/bin/env python
import gmaillib
from collections import Counter
from wordcloud import WordCloud
import matplotlib.pyplot as plt

amount = 100
cnt = Counter()
username = raw_input("Gmail account: ")
password = raw_input("Password: ")

account = gmaillib.account(username, password)

emails = account.inbox(0, amount)

data = ""
for email in emails:
  data = data + str(email.body)

wordcloud = WordCloud().generate(data)
plt.imshow(wordcloud)
plt.axis("off")
plt.show()</pre><p></p>
<p><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Fcreating-a-gmail-wordcloud%2F&amp;linkname=Creating%20a%20gmail%20wordcloud" title="Facebook" rel="nofollow" target="_blank"></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Fcreating-a-gmail-wordcloud%2F&amp;linkname=Creating%20a%20gmail%20wordcloud" title="Twitter" rel="nofollow" target="_blank"></a><a class="a2a_button_google_plus" href="http://www.addtoany.com/add_to/google_plus?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Fcreating-a-gmail-wordcloud%2F&amp;linkname=Creating%20a%20gmail%20wordcloud" title="Google+" rel="nofollow" target="_blank"></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Fcreating-a-gmail-wordcloud%2F&amp;linkname=Creating%20a%20gmail%20wordcloud" title="Reddit" rel="nofollow" target="_blank"></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Fcreating-a-gmail-wordcloud%2F&amp;linkname=Creating%20a%20gmail%20wordcloud" title="StumbleUpon" rel="nofollow" target="_blank"></a><a class="a2a_button_pinterest" href="http://www.addtoany.com/add_to/pinterest?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Fcreating-a-gmail-wordcloud%2F&amp;linkname=Creating%20a%20gmail%20wordcloud" title="Pinterest" rel="nofollow" target="_blank"></a><a class="a2a_dd a2a_target addtoany_share_save" href="https://www.addtoany.com/share_save#url=http%3A%2F%2Ftalkera.org%2Fpython%2Fcreating-a-gmail-wordcloud%2F&amp;title=Creating%20a%20gmail%20wordcloud" id="wpa2a_2"></a></p>]]></content:encoded>
			<wfw:commentRss>https://talkera.org/python/creating-a-gmail-wordcloud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Requests: HTTP for Humans</title>
		<link>https://talkera.org/python/requests-http-for-humans/</link>
		<comments>https://talkera.org/python/requests-http-for-humans/#comments</comments>
		<pubDate>Tue, 23 Dec 2014 15:32:06 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">https://talkera.org/python/?p=5</guid>
		<description><![CDATA[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&#8217;s powered by httplib and urllib3, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>If you want to request data from webservers, the traditional way to do that in Python is using the <em>urllib</em> library. While this library is effective, you could easily create more complexity than needed when building something. Is there another way?</p>
<p><a href="https://github.com/kennethreitz/requests" target="_blank">Requests</a> is an Apache2 Licensed HTTP library, written in Python. It&#8217;s powered by httplib and <a href="https://github.com/shazow/urllib3">urllib3</a>, but it does all the hard work and crazy hacks for you.</p>
<p>To install type:</p><pre class="crayon-plain-tag">git clone https://github.com/kennethreitz/requests.git
cd requests
sudo python setup.py install</pre><p>The Requests library is now installed. We will list some examples below:</p>
<p><strong>Grabbing raw html using HTTP/HTTPS requests</strong><br />
We can now query a website as :</p><pre class="crayon-plain-tag">import requests
r = requests.get('https://talkera.org/python/')
print r.content</pre><p>Save it and run with:</p><pre class="crayon-plain-tag">python website.py</pre><p>It will output the raw HTML code.</p>
<p><strong>Download binary image using Python</strong></p><pre class="crayon-plain-tag">from PIL import Image
from StringIO import StringIO
import requests

r = requests.get('http://1.bp.blogspot.com/_r-MQun1PKUg/SlnHnaLcw6I/AAAAAAAAA_U$
i = Image.open(StringIO(r.content))
i.show()</pre><p><a href="/python/wp-content/uploads/2014/12/python.png"><img class="size-medium wp-image-12" src="/python/wp-content/uploads/2014/12/python-300x292.png" alt="python" width="300" height="292" /></a></p>
<p>An image retrieved using python</p>
<p><strong>Website status code (is the website online?)</strong></p><pre class="crayon-plain-tag">import requests
r = requests.get('https://talkera.org/python/')
print r.status_code</pre><p>This returns 200 (OK). A list of status codes can be found here: <a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes" target="_blank">https://en.wikipedia.org/wiki/List_of_HTTP_status_codes</a></p>
<p><strong>Retrieve JSON from a webserver </strong><br />
You can easily grab a JSON object from a webserver.</p><pre class="crayon-plain-tag">import requests

import requests
r = requests.get('https://api.github.com/events')
print r.json()</pre><p><strong>HTTP Post requests using Python</strong></p><pre class="crayon-plain-tag">from StringIO import StringIO
import requests

payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.post("http://httpbin.org/post", data=payload)
print(r.text)</pre><p><strong>SSL verification, verify certificates using Python</strong></p><pre class="crayon-plain-tag">from StringIO import StringIO
import requests
print requests.get('https://github.com', verify=True)</pre><p>&nbsp;</p>
<p><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Frequests-http-for-humans%2F&amp;linkname=Requests%3A%20HTTP%20for%20Humans" title="Facebook" rel="nofollow" target="_blank"></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Frequests-http-for-humans%2F&amp;linkname=Requests%3A%20HTTP%20for%20Humans" title="Twitter" rel="nofollow" target="_blank"></a><a class="a2a_button_google_plus" href="http://www.addtoany.com/add_to/google_plus?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Frequests-http-for-humans%2F&amp;linkname=Requests%3A%20HTTP%20for%20Humans" title="Google+" rel="nofollow" target="_blank"></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Frequests-http-for-humans%2F&amp;linkname=Requests%3A%20HTTP%20for%20Humans" title="Reddit" rel="nofollow" target="_blank"></a><a class="a2a_button_stumbleupon" href="http://www.addtoany.com/add_to/stumbleupon?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Frequests-http-for-humans%2F&amp;linkname=Requests%3A%20HTTP%20for%20Humans" title="StumbleUpon" rel="nofollow" target="_blank"></a><a class="a2a_button_pinterest" href="http://www.addtoany.com/add_to/pinterest?linkurl=http%3A%2F%2Ftalkera.org%2Fpython%2Frequests-http-for-humans%2F&amp;linkname=Requests%3A%20HTTP%20for%20Humans" title="Pinterest" rel="nofollow" target="_blank"></a><a class="a2a_dd a2a_target addtoany_share_save" href="https://www.addtoany.com/share_save#url=http%3A%2F%2Ftalkera.org%2Fpython%2Frequests-http-for-humans%2F&amp;title=Requests%3A%20HTTP%20for%20Humans" id="wpa2a_4"></a></p>]]></content:encoded>
			<wfw:commentRss>https://talkera.org/python/requests-http-for-humans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
