<?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>maSnun.com</title>
	<atom:link href="http://masnun.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://masnun.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 11 Mar 2010 17:24:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Python on Hostmonster, Umbrahosting And Other General  Shared Hosting</title>
		<link>http://masnun.com/blog/2010/03/11/using-python-on-hostmonster-umbrahosting-and-other-general-shared-hosting/</link>
		<comments>http://masnun.com/blog/2010/03/11/using-python-on-hostmonster-umbrahosting-and-other-general-shared-hosting/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 17:17:46 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://masnun.com/blog/?p=835</guid>
		<description><![CDATA[I&#8217;ve a hostmonster and umbrahosting shared hosting where my sites are running smoothly in PHP. I&#8217;m perfectly happy with both UmbraHosting and HostMonster. Additionally both the hosting providers have Python support. Being a Python enthusiast, I decided to check out.
On both Hostmonster and Umbrahosting, you can execute Python scripts as CGI scripts. But you must [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve a hostmonster and umbrahosting shared hosting where my sites are running smoothly in PHP. I&#8217;m perfectly happy with both UmbraHosting and HostMonster. Additionally both the hosting providers have Python support. Being a Python enthusiast, I decided to check out.</p>
<p>On both Hostmonster and Umbrahosting, you can execute Python scripts as CGI scripts. But you must take care of these points:</p>
<p>&#8211; They must be placed inside the cgi-bin directory.<br />
&#8211; Permission should be 755. (777 triggered server error for me)</p>
<p>I didn&#8217;t find the latest version of Python anywhere on these two hosts. Let alone Python 2.5, they have Python 2.4. <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  But still I&#8217;m happy that I can run Python. The only thing that I didn&#8217;t like was the obligation to put my scripts in the cgi-bin directory. So, I couldn&#8217;t have URLs like http://masnun.com/hello.py <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Later today afternoon, an idea clicke in my mind. Can&#8217;t I target a subdomain to the cgi-bin directory? The answer is: YES! Just use a .htaccess file to map certain urls to your cgi-bin directory.</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) cgi-bin/$1 [L]
&lt;/IfModule&gt;</pre></div></div>

<p>Putting the .htaccess in your domain&#8217;s root directory will allow you to put a python file inside your cgi-bin directory and visit it from http://example.com/example.py <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/03/11/using-python-on-hostmonster-umbrahosting-and-other-general-shared-hosting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending SMS With AloAshbei Platform (GP APIs) and PHP</title>
		<link>http://masnun.com/blog/2010/02/04/sending-sms-with-aloashbei-platform-gp-apis-and-php/</link>
		<comments>http://masnun.com/blog/2010/02/04/sending-sms-with-aloashbei-platform-gp-apis-and-php/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 12:41:21 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=833</guid>
		<description><![CDATA[Here&#8217;s a working example of Grameen Phone&#8217;s AloAshbei Platform.

&#160;
&#60;?php
/*
* Demo of the SMS API
* Author: maSnun
* URL: http://masnun.com
*/
&#160;
&#160;
// I hosted the WSDL on my own host
$soap = new SoapClient&#40;&#34;http://masnun.com/wsdl/wsdl.php&#34;&#41;;
&#160;
// Set the parameters in an array
&#160;
$a&#91;'registrationID'&#93; = &#34;masnun&#34;;
$a&#91;'password'&#93; = &#34;******&#34;;
$a&#91;'sourceMsisdn'&#93; = '8801711960803';
$a&#91;'destinationMsisdn'&#93; = '88017********';
$a&#91;'smsPort'&#93; = 7424;
$a&#91;'msgType'&#93; = 4;
$a&#91;'charge'&#93; = 2.00 ;
$a&#91;'chargedParty'&#93; = '8801711960803';
$a&#91;'contentArea'&#93; = 'gpgp_psms';
$a&#91;'msgContent'&#93; = [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a working example of Grameen Phone&#8217;s AloAshbei Platform.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
* Demo of the SMS API
* Author: maSnun
* URL: http://masnun.com
*/</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// I hosted the WSDL on my own host</span>
<span style="color: #000088;">$soap</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://masnun.com/wsdl/wsdl.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the parameters in an array</span>
&nbsp;
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'registrationID'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;masnun&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;******&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sourceMsisdn'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'8801711960803'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'destinationMsisdn'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'88017********'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'smsPort'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7424</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msgType'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'charge'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color:#800080;">2.00</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'chargedParty'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'8801711960803'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'contentArea'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'gpgp_psms'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'msgContent'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hello GP API!'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
try <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$soap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendSMS</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SendSMSRequest&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Example Response:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&nbsp;
masnun@ubuntu:~$ cd random
masnun@ubuntu:~/random$ php gpsoap.php
object(stdClass)#2 (1) {
  [&quot;SendSMSResponse&quot;]=&gt;
  object(stdClass)#3 (2) {
    [&quot;status&quot;]=&gt;
    string(2) &quot;OK&quot;
    [&quot;msgID&quot;]=&gt;
    string(17) &quot;20100204183047653&quot;
  }
}
masnun@ubuntu:~/random$</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/02/04/sending-sms-with-aloashbei-platform-gp-apis-and-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hosting your Twitter Bots on Google App Engine</title>
		<link>http://masnun.com/blog/2010/02/02/hosting-your-twitter-bots-on-google-app-engine/</link>
		<comments>http://masnun.com/blog/2010/02/02/hosting-your-twitter-bots-on-google-app-engine/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 11:45:56 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=829</guid>
		<description><![CDATA[UPDATE:  Download  the improved version of the application. I have made some code changes after the blog post got posted to reddit. The source code is now more readable and the app  easily configurable.

I am amazed to see the implementation of cron jobs on Google App Engine. I was hosting my twitter [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE: </strong> <a href="http://masnun.googlecode.com/files/twitter_bot_gae_v2.zip">Download</a>  the improved version of the application. I have made some code changes after the blog post got posted to reddit. The source code is now more readable and the app  easily configurable.</p>
<hr />
<p>I am amazed to see the implementation of cron jobs on Google App Engine. I was hosting my twitter bots on my paid shared hosting. My scripts were written in php and they were run via cron jobs set from my cPanel. Of course the cPanel cron UI is now quite familiar to me, to us who use it very often. But as a matter of fact, I can&#8217;t run per minute cron on my host. I should have a minimum interval of 15 minutes between two execution of the same cron job. I was amazed when I first discovered that Google App Engine lets me run cron every minute. Since they calculate my usage in different types of quotas, they hardly care about how often you schedule your cron. So, I decided to port my twitter bots to GAE and Python.</p>
<p>The idea was pretty simple. I already had a Yahoo! Pipe setup which mashes up multiple RSS feeds into one. My app will be collecting data from the pipe in JSON format. Then it&#8217;ll check the last tweeted entry and tweet the newer entries. Pretty straightforward algorithm. I registered a new application for my bots and started developing it on my local machine.</p>
<p>I integrated the u.nu url shortening service with their API quite easily. Though Python 2.6.2 has a built in module for JSON handling, Python 2.5 doesn&#8217;t have it. So, I had to install simplejson for JSON decoding. Later, I moved on to finding a good twitter client for my app. I first tried python-twitter. I have previously used it and it worked fine. But the application was generating some error messages when I integrated into GAE. I was puzzled and tried to find if there was something wrong in my coding. After about an hour, I concluded that my code was okay! There&#8217;s something wrong with the client. A bit of googling revealed that &#8220;python-twitter&#8221; doesn&#8217;t work on GAE without any hacks :&#8217;(. I had to find an alternative and I chose tweepy for that. It was working fine with the app.</p>
<p>Finally after 3 hours, the app was ready and it&#8217;s working! GAE doesn&#8217;t permit long execution period for a process, so I had to decrease the amount of tweets per request. But I covered that up by setting a more frequent cron job <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I would try the new taskqueue API soon to see if that has any help for my app.</p>
<p>My twitter bots have proved handy in the past and it feels great that I can host them on a scalable and efficient platform like Google App Engine &#8212; without paying a single dollar per month! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>Download Source :</strong> <a href="http://masnun.googlecode.com/files/Twitter_BOT_GAE.zip">http://masnun.googlecode.com/files/Twitter_BOT_GAE.zip</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/02/02/hosting-your-twitter-bots-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building a Jabber Bot (Google Talk) with Python and Google App Engine</title>
		<link>http://masnun.com/blog/2010/02/01/building-a-jabber-bot-google-talk-with-python-and-google-app-engine/</link>
		<comments>http://masnun.com/blog/2010/02/01/building-a-jabber-bot-google-talk-with-python-and-google-app-engine/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 21:52:13 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=820</guid>
		<description><![CDATA[To develop a Jabber / Google Talk Bot, we first need to enable the XMPP inbound service for the application. Just add the lines:

inbound_services:
- xmpp_message

to your app.yaml file. That would activate the service for our application. Have a look at my application&#8217;s app.yaml file:

&#160;
application: masnun-test
version: 3
runtime: python
api_version: 1
&#160;
handlers:
- url: .*
  script: masnun.py
&#160;
inbound_services:
- xmpp_message

Now, we [...]]]></description>
			<content:encoded><![CDATA[<p>To develop a Jabber / Google Talk Bot, we first need to enable the XMPP inbound service for the application. Just add the lines:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">inbound_services:
- xmpp_message</pre></div></div>

<p>to your app.yaml file. That would activate the service for our application. Have a look at my application&#8217;s app.yaml file:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">&nbsp;
application: masnun-test
version: 3
runtime: python
api_version: 1
&nbsp;
handlers:
- url: .*
  script: masnun.py
&nbsp;
inbound_services:
- xmpp_message</pre></div></div>

<p>Now, we have the app configured, we need to do the actual coding. Every GAE app has it&#8217;s own IM id: [application_id]@appspot.com <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  There are other extensive IDs also available but for this task we will use this format. So, my app has the ID: masnun-test@appspot.com as it&#8217;s Jabber / Google Talk ID. If the user adds this ID to his/her contact list, it&#8217;ll auto accept the friend invitation and appear online. Now when he/she sends a message, the message is sent as a POST request to the url: /_ah/xmpp/message/chat/ . This URL is not publicly accessible without admin rights. Our app can handle this URL like any other URL. So we need to setup a request handler for any POST request to this URL.</p>
<p>GAE has a nice API for it&#8217;s XMPP service which lets us build a Message object directly from the POSTed data. We will do that. Extract the message parts and send a response back. Here is source code for &#8220;masnun.py&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">cgi</span>
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">api</span> <span style="color: #ff7700;font-weight:bold;">import</span> xmpp
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span> <span style="color: #ff7700;font-weight:bold;">import</span> webapp
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span>.<span style="color: black;">webapp</span>.<span style="color: black;">util</span> <span style="color: #ff7700;font-weight:bold;">import</span> run_wsgi_app
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> XMPPHandler<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> post<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        message = xmpp.<span style="color: black;">Message</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">POST</span><span style="color: black;">&#41;</span>
        sender = <span style="color: #dc143c;">cgi</span>.<span style="color: black;">escape</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'from'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
        body = message.<span style="color: black;">body</span>
        message.<span style="color: black;">reply</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello, &quot;</span> + sender + <span style="color: #483d8b;">&quot;!, you sent: &quot;</span> + message.<span style="color: black;">body</span><span style="color: black;">&#41;</span>
&nbsp;
application = webapp.<span style="color: black;">WSGIApplication</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/_ah/xmpp/message/chat/'</span>, XMPPHandler<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>,
                                     debug=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    run_wsgi_app<span style="color: black;">&#40;</span>application<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/02/01/building-a-jabber-bot-google-talk-with-python-and-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Handling JSON in Python</title>
		<link>http://masnun.com/blog/2010/01/30/handling-json-in-python/</link>
		<comments>http://masnun.com/blog/2010/01/30/handling-json-in-python/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 17:41:18 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=814</guid>
		<description><![CDATA[On php, I just use json_encode() and json_decode() to handle JSON data with ease. Python has a built in module named &#8220;json&#8221; for the same purpose. Here&#8217;s the link for the official documentation: http://docs.python.org/library/json.html   The documentation has pretty examples. Still, I wanted to try things out by myself. I used Python to parse [...]]]></description>
			<content:encoded><![CDATA[<p>On php, I just use json_encode() and json_decode() to handle JSON data with ease. Python has a built in module named &#8220;json&#8221; for the same purpose. Here&#8217;s the link for the official documentation: <a href="http://docs.python.org/library/json.html">http://docs.python.org/library/json.html</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  The documentation has pretty examples. Still, I wanted to try things out by myself. I used Python to parse the JSON output of a certain Yahoo! Pipes feed :</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> json,<span style="color: #dc143c;">urllib</span>
data = <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://pipes.yahoo.com/pipes/pipe.run?_id=a0b9e3295664870ee81711aed6f7ecd6&amp;_render=json&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
d = json.<span style="color: black;">loads</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> d<span style="color: black;">&#91;</span><span style="color: #483d8b;">'value'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'items'</span><span style="color: black;">&#93;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> x<span style="color: black;">&#91;</span><span style="color: #483d8b;">'title'</span><span style="color: black;">&#93;</span></pre></div></div>

<p>Output:</p>
<pre>
masnun@ubuntu:~/Desktop$ python jsontest.py
Sms Plugin
..........
[SNIP]
..........
Profit Spreadsheet
Graphic Web Des. Needed Fast
Customer Ordering Website
Dating Site Profiles
masnun@ubuntu:~/Desktop$
</pre>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/01/30/handling-json-in-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Created Another WordPress Theme</title>
		<link>http://masnun.com/blog/2010/01/30/created-another-wordpress-theme/</link>
		<comments>http://masnun.com/blog/2010/01/30/created-another-wordpress-theme/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 14:37:56 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=808</guid>
		<description><![CDATA[I have finally chosen web application engineering as my core subject of specialization. I have always appreciated the beauty and usability of web applications. You can easily paint your dreams on a web page, rather than on a desktop software. I have been developing mobile web sites for over 3 years now. I loved playing [...]]]></description>
			<content:encoded><![CDATA[<p>I have finally chosen web application engineering as my core subject of specialization. I have always appreciated the beauty and usability of web applications. You can easily paint your dreams on a web page, rather than on a desktop software. I have been developing mobile web sites for over 3 years now. I loved playing with WML and later XHTML along with bits of HTML. Later, when I realized that I have a good command over PHP, I looked at the web industry. I introduced myself to serious web development through my free lance career. The very first free lance job I got, involved setting a javascript countdown timer. I had to design the page and install the counter with a newsletter subscription form. I was in a mess with HTML and CSS. I was a newbie that time. (In fact, even today I don&#8217;t know much designing). Luckily the project was very simple and I didn&#8217;t have to code much. But still I got paid $30 <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I was inspired and started looking for more and more free lance jobs. Given my lackings in web design skills, I tried to find only projects which required programming alone. But I had little luck. I always had to play with bits of designing on almost all the projects. Gradually, I started learning HTML and CSS over time. When I joined Leevio, <a href="http://hasin.wordpress.com">Hasin Vai</a> introduced me to massive designing trends. I was amazed to see the beauty of web designs.</p>
<p>I was using WordPress for my personal website for a long time. I was always interested in the WP API. But somehow I couldn&#8217;t make up my mind to do something with the API. Hasin vai inspired me a lot to work on WordPress. Finally, on a good day, I managed to build my first WP plugin &#8212; &#8220;gaf-text-link&#8221;. The plugin was featured by GAF and is available from the affiliates page of GAF (Now, freelancer.com). GAF paid me $100 appreciating my work as a marketing of their service. I was damn motivated to work on WordPress again &#8212; because of the money. Whenever I looked at the job listing at my favorite free lance sites, WP related projects were available in a large numbers and many of them involved good price <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  My desire to work with WP grew.</p>
<p>I later created another plugin to integrate admob ads into WP. Hasin Vai one day gave me links to a bunch of nice of books on WP. They were great and I really learnt a lot. I coded up my first WP theme which was being used on this site until yesterday night.</p>
<p>From yesterday, I started working to improve my design skills. I started with WP theme design so that I can gather knowledge on two topics from a single work. I have got decent command over CSS based styling now, but I am still falling short in layout designing. My design last night was not up to mark, at least it was not what I wanted. Hasin vai suggested me to use a CSS framework for layout. I had two primary options &#8212; fluid.gs for fluid layout and 960.gs for fixed width layout. I chose 960.gs since I wanted my layout to be fixed width. It was cool working with it. It saved me a lot of time and let me do what I really wanted to do! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  I am not willing to use raw CSS for layout again <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Not only CSS and HTML, I have also worked with GIMP for bit of image editing. I am very new to GIMP. Had to struggle a bit with the interface. I hope I will be able to cope up really soon.</p>
<p>I finished the theme just a few hours ago. I made it widget-ready this time. It&#8217;s not bad for me! I will keep digging with designs and see if I can come with something better <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/01/30/created-another-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A Simple Web Server in 30 Lines of Python Code</title>
		<link>http://masnun.com/blog/2010/01/16/a-simple-web-server-in-30-lines-of-python-code/</link>
		<comments>http://masnun.com/blog/2010/01/16/a-simple-web-server-in-30-lines-of-python-code/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 11:57:28 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=800</guid>
		<description><![CDATA[I haven&#8217;t recently had much time to do the fancy R&#038;Ds I always loved! Today afternoon I was not feeling good to study, let alone that huge microeconomics assignment. I fired off the python interpreter and started coding aimlessly. I was inspecting the http.server module of Python 3 when an urge to create a web [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t recently had much time to do the fancy R&#038;Ds I always loved! Today afternoon I was not feeling good to study, let alone that huge microeconomics assignment. I fired off the python interpreter and started coding aimlessly. I was inspecting the http.server module of Python 3 when an urge to create a web server popped into my mind. I started studying the Python 2.X docs and soon coded up a very simple web server. It can parse and serve dynamic pages (currently php, py and pyc files). It can not yet serve static files. <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   And one more issue: If you run a phpinfo() with it, you won&#8217;t get a good looking output like you get on a LAMP, WAMP or MAMP.</p>
<p>To start the server, just use this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python server.py</pre></div></div>

<p>Source Code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">BaseHTTPServer</span> <span style="color: #ff7700;font-weight:bold;">import</span> HTTPServer, BaseHTTPRequestHandler
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>,<span style="color: #dc143c;">glob</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> RequestHandler<span style="color: black;">&#40;</span>BaseHTTPRequestHandler<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> do_GET<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        fpath = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">getcwd</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">self</span>.<span style="color: black;">path</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        response = <span style="color: #483d8b;">&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">isfile</span><span style="color: black;">&#40;</span>fpath<span style="color: black;">&#41;</span>:
                response = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>fpath,<span style="color: #483d8b;">&quot;rb&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> fpath<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">3</span>:<span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'php'</span>:
                    response = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;php5 -f &quot;</span> + fpath<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> fpath<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">2</span>:<span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'py'</span>:
                    response = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;python &quot;</span> + fpath<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> fpath<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">3</span>:<span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'pyc'</span>:
                    response = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;python &quot;</span> + fpath<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">isdir</span><span style="color: black;">&#40;</span>fpath<span style="color: black;">&#41;</span>:
                dirlist = <span style="color: #dc143c;">glob</span>.<span style="color: #dc143c;">glob</span><span style="color: black;">&#40;</span>fpath + <span style="color: #483d8b;">&quot;/*&quot;</span><span style="color: black;">&#41;</span>
                response = <span style="color: #483d8b;">&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Directory Listing of &quot;</span> + <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">basename</span><span style="color: black;">&#40;</span>fpath<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&lt;/title&gt;&lt;head&gt;&quot;</span>
                response += <span style="color: #483d8b;">&quot;&lt;body&gt;&quot;</span>
                <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> dirlist:
                    response += <span style="color: #483d8b;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> + <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">basename</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span> + <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">basename</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&lt;/a&gt;&lt;br /&gt;&quot;</span>
                response += <span style="color: #483d8b;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">send_response</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">send_header</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Content-type&quot;</span>,<span style="color: #483d8b;">&quot;text/html&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">end_headers</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">wfile</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>response<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
httpd = HTTPServer<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,<span style="color: #ff4500;">7676</span><span style="color: black;">&#41;</span>,RequestHandler<span style="color: black;">&#41;</span>
httpd.<span style="color: black;">serve_forever</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>I love you, Python! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/01/16/a-simple-web-server-in-30-lines-of-python-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A reflect() Function For Quick Reflection in PHP</title>
		<link>http://masnun.com/blog/2010/01/05/a-reflect-function-for-quick-reflection-in-php/</link>
		<comments>http://masnun.com/blog/2010/01/05/a-reflect-function-for-quick-reflection-in-php/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 15:25:43 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=798</guid>
		<description><![CDATA[The Reflection API is the perfect way to reverse engineer and inspect php objects and functions. I have written a function to quickly pass params to the Reflection API and get things done.
Here&#8217;s the source codes:

&#160;
&#60;?php
&#160;
function reflect&#40;$data,$return = false&#41; &#123;
    $string = &#34;\n \nReflecting: {$data} \n&#34;;
    $string .= &#34;\n====================\n&#34;;
 [...]]]></description>
			<content:encoded><![CDATA[<p>The Reflection API is the perfect way to reverse engineer and inspect php objects and functions. I have written a function to quickly pass params to the Reflection API and get things done.</p>
<p>Here&#8217;s the source codes:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> reflect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> <span style="color: #000099; font-weight: bold;">\n</span>Reflecting: <span style="color: #006699; font-weight: bold;">{$data}</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>====================<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> Reflection<span style="color: #339933;">::</span><span style="color: #004000;">export</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>====================<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> Reflection<span style="color: #339933;">::</span><span style="color: #004000;">export</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionFunction<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>====================<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$return</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/01/05/a-reflect-function-for-quick-reflection-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Track Your Favorite Topic on Twitter: A PHP CLI Tool</title>
		<link>http://masnun.com/blog/2010/01/03/track-your-favorite-topic-on-twitter-a-php-cli-tool/</link>
		<comments>http://masnun.com/blog/2010/01/03/track-your-favorite-topic-on-twitter-a-php-cli-tool/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 16:49:42 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=794</guid>
		<description><![CDATA[Here&#8217;s a little php utility that will let you watch the Twitter public time line for your favorite topic. This is specially helpful for those who want to build some tracking application on the basis of the twitter streaming APIs.
Here&#8217;s the source:

&#60;?php
$topic = $argv&#91;1&#93;;
if&#40;empty &#40;$topic&#41;&#41; &#123;
    $topic = &#34;php&#34;;
&#125;
$username = &#34;twitter_username&#34;;
$password = [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little php utility that will let you watch the Twitter public time line for your favorite topic. This is specially helpful for those who want to build some tracking application on the basis of the twitter streaming APIs.</p>
<p>Here&#8217;s the source:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$topic</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$topic</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$topic</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;twitter_username&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;twitter_password&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://<span style="color: #006699; font-weight: bold;">{$username}</span>:<span style="color: #006699; font-weight: bold;">{$password}</span>@stream.twitter.com/1/statuses/filter.json?track=<span style="color: #006699; font-weight: bold;">{$topic}</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tweet</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'screen_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$tweet</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; <span style="color: #000099; font-weight: bold;">\n</span> -------------------- <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Run this script with the keyword as the argument:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php twitter.php keyword</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/01/03/track-your-favorite-topic-on-twitter-a-php-cli-tool/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Twitter Streaming API with Python</title>
		<link>http://masnun.com/blog/2010/01/03/twitter-streaming-api-with-python/</link>
		<comments>http://masnun.com/blog/2010/01/03/twitter-streaming-api-with-python/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 16:02:19 +0000</pubDate>
		<dc:creator>maSnun</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://masnun.com/?p=788</guid>
		<description><![CDATA[Hasin Vai has a good post about collecting tweets in real time with php. Here&#8217;s the post: http://hasin.wordpress.com/2009/06/20/collecting-data-from-streaming-api-in-twitter/   If you are a php developer look into there.
Well, I am going to cover Python for the Twitter streaming API. You need the &#8220;tweetstream&#8221; python module which depends on the &#8220;anyjson&#8221; module. Please make sure [...]]]></description>
			<content:encoded><![CDATA[<p>Hasin Vai has a good post about collecting tweets in real time with php. Here&#8217;s the post: <a href="http://hasin.wordpress.com/2009/06/20/collecting-data-from-streaming-api-in-twitter/">http://hasin.wordpress.com/2009/06/20/collecting-data-from-streaming-api-in-twitter/</a> <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If you are a php developer look into there.</p>
<p>Well, I am going to cover Python for the Twitter streaming API. You need the &#8220;tweetstream&#8221; python module which depends on the &#8220;anyjson&#8221; module. Please make sure you have these modules installed before you proceed.</p>
<p>Download Links: <a href="http://pypi.python.org/pypi/anyjson">anyjson</a> |  <a href="http://pypi.python.org/pypi/tweetstream/">tweetstream</a></p>
<p>To install these packages, use the built in setup.py of the individual packages :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>In my case, I didn&#8217;t have the &#8220;setuptools&#8221; python module installed with my default python installation. So I had to install it to get the setup.py work:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python-setuptools</pre></div></div>

<p>I love the magic of debian packages <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now, you can install the modules and dive into our example:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> tweetstream
&nbsp;
stream = tweetstream.<span style="color: black;">TweetStream</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;twitter_username&quot;</span>, <span style="color: #483d8b;">&quot;twitter_password&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> tweet <span style="color: #ff7700;font-weight:bold;">in</span> stream:
    <span style="color: #ff7700;font-weight:bold;">if</span> tweet.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;text&quot;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> tweet<span style="color: black;">&#91;</span><span style="color: #483d8b;">'user'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'screen_name'</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;: &quot;</span> + tweet<span style="color: black;">&#91;</span><span style="color: #483d8b;">'text'</span><span style="color: black;">&#93;</span> , <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;-----&quot;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">4</span></pre></div></div>

<p>That&#8217;s it! In real, you get the stream dictionary which you can use to manipulate the tweets.</p>
<p>The &#8220;tweetstream&#8221; module also lets you access the Track and Follow APIs in a superb fashion!</p>
<p>I love Twitter, I love Python! <img src='http://masnun.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://masnun.com/blog/2010/01/03/twitter-streaming-api-with-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
