Categories
Python

Twitter Streaming API with Python

Hasin Vai has a good post about collecting tweets in real time with php. Here’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 “tweetstream” python module which depends on the “anyjson” module. Please make sure you have these modules installed before you proceed.

Download Links: anyjson | tweetstream

To install these packages, use the built in setup.py of the individual packages :

In my case, I didn’t have the “setuptools” python module installed with my default python installation. So I had to install it to get the setup.py work:

I love the magic of debian packages 🙂

Now, you can install the modules and dive into our example:

That’s it! In real, you get the stream dictionary which you can use to manipulate the tweets.

The “tweetstream” module also lets you access the Track and Follow APIs in a superb fashion!

I love Twitter, I love Python! 🙂

Categories
PHP

PHP: Setting the include_path for quick includes

PHP being the first language I loved and used for a long time, I now use it for all sorts of purposes. I also love and use Python but very often I end up coding in php because I am more habituated to this language than the beautiful python 🙂 Again for some simple tasks, php is loads better than Python. Just imagine you need the md5 hash of a string. Will you import the hashlib first, then go through the md5() and hexdigest() methods ? Nope. I will simply fire off a php interactive shell and use the built in md5() function with an echo.

One of the major problems I was facing that all the external libs I use, I have to copy them into my current working directory or have to use some other techniques to import them into my current script.

To get a permanent work around this problem, I decided to use the include_path directive in php.ini 🙂 I created a directory named “phplib” under my home directory and put all the libs in there.

Next, I opened up /etc/php5/conf.d/ with root access and added a new file named phplib.ini with the following contents:

Now, whenever I need a library loaded, I just type :

That imports the mailer class, even on my interactive php shell 🙂

PS: Well, since the php interpreter always has your home directory as the CWD, you could just use include(“phplib/mailer.php”); in this case. But what about the php module running with apache? The include_path affects that one as well. It helps! But also it has a negative side. Make sure you upload the respective libs to the web server before you deploy your web application on the production box! 😀

Categories
Uncategorized

The Google Go Experience

I have always wanted to check out the Go language sooner but unfortunately enough couldn’t have a go… Today I googled if there are any debian packages for Google Go and luckily I found one… It’s of course not an official release from the Go team. Still it interested me. I downloaded the file and installed the package. Yeah, it works! This is the first time I am playing with Go, so no issues have been encountered. But the debian package requires me to overwrite some of the GCC files. Again, I am not a serious C/C++ programmer, so I don’t know if that has damaged my GCC to any extent.

Oh yeah, I forgot to mention I am on Ubuntu 9.04 🙂 I downloaded the package from this link: http://drop.io/gccgodeb/asset/gccgo-4-5-0-1-i386-deb

It’s nearly a 27 MB of download. I downloaded and double clicked to install it. The installation failed with some errors. So, I pointed back to the Original Source Page (Author’s Blog Post) of the package and re-read carefully. I had to use the command line to set “–force-overwrite” mode to the dpkg utility so that it could overwrite files at it’s discretion. Here’s the command:

Now, for quick demo, I downloaded the sample “Hello World!” source code from the official Go website at http://golang.org/ 🙂 (Hey, wasn’t it http://go-lang.org the last time I visited it? No way, both URL works now 😀 )

PS: I am sorry that my Syntax Highlighter doesn’t yet have the Go syntax highlighting patterns. Neither does my code editor! But still I used the code block, just out of a good practice! 😛

Then I compiled the source (after naming it masnun.go) with the following command:

It created the file a.out . I ran it from the command line again:

It was pretty easy in fact! I am going to play with Go at my leisure to check out what it has to provide the developers with… I love Python, let’s see if Go can give me anything more than Python 🙂

Thanks to Google, we have another programming language to do our bidding! Happy programming!