Twitter Weather station

Create your own weather station on Twitter.

With these few simple steps and this following code, you can have the weather information from where live automatically updated to you twitter account. These following steps are for a Unix/Linux/Mac environment but I am sure they can easily adapted on Windows.
 
Posted on Feb 17, 2009 by: Fred Cirera @ 22:35 Leave a comment Comments: 28

Print messages on a mini LCD.

At work, I manage a cluster of several hundred nodes. All those nodes are equipped with a little LCD display, like to one showed in the picture on the right. Until now, these displays were only displaying the name of the cluster vendor at boot, and the node name when the machine was up an running. To put these neat little displays to better use, I wrote a Python program named lcd.py, which prints more useful information.

When started, lcd.py burns into the MVRAM of the display the name of the company I am working for and the name of the node, which is in fact the position of the node in the rack. This helps me find which node is which when I take several of them out of the rack for maintenance. I just power the machine for a few seconds to read its name and position on the racks on the LCD display .

Then, the daemon goes into an infinite loop to probe the disk temperature using the S.M.A.R.T information provided by the disk. This information is then displayed on the second line of the LCD display. A quick look at the display and I know if something is wrong with the disk or the machine. Of course this is not the only monitoring system used to watch the system but every little detail helps. And it is fun to use these little displays.

The program also pings the “master node” to see if there are any network problems. If the “master node” cannot be reached, the program turns off the LCD display backlight. A quick glance at the entire rack and you know which node is in trouble.

For more information on these LCD display you can download the manual.

Download the entire source code

 
Posted on Feb 13, 2009 by: Fred Cirera @ 22:18 Leave a comment Comments: 10

Heartbeat code for cluster environment

Working in a cluster environment, I often need to check in my Python programs, if some of the nodes of my cluster are dead or live. To do so I have in my Python toolbox, a class called Heartbeat. This is a simple heartbeat class does a ping on the cluster node, and return True, or false depending on the health of the targeted node. This class implement a stripped down version of ping. It send a ICMP_ECHO_REQUEST packet and wait for the answer.

To use this call I call the constructor with the node name, or IP address, followed by the number of seconds between heartbeats. Then every time I need to check in my program if the node is still alive, I call the method is_alive() which returns a Boolean.
 
Posted on Jan 31, 2009 by: Fred Cirera @ 23:46 Leave a comment Comments: 11

Fortune cookies on Twitter (part 2)

A couple of day ago I posted an article Unix fortune cookies on twitter containing the source code for a Python script allowing you to post Unix type fortune cookies to your Twitter account.

In that code, I was using a package called fortune developed by Brian M. Clapper. The problem is that this package does not allow you to use the existing fortunes files provided by your operating system. The .dat file used by that package are not compatible with the .dat file of your operating system. Also the actual version of the package contains a bug and the creation of the .dat file doesn't work. That's why I developed the following get_fortune() function, which can use the operating system's fortunes files.
 
Posted on Dec 07, 2008 by: Fred Cirera @ 14:00 Leave a comment Comments: 28

Unix fortune cookies on Twitter.

I just wrote a new script called twfortune. It chooses a random fortune, as the fortune(8) program in the BSD-games package does, and send it to your twitter account as a message of the day (motd)
You can download the complete script and a sample fortunes file from this link.
http://velvnet.com/c

 
Posted on Dec 03, 2008 by: Fred Cirera @ 15:03 Leave a comment Comments: 25

Short url encoder

I just opened http://kiq.me/, a new service developed in Python, with Turbogears framework. Kiq.me allows you to encode a very long URL (web address) into a shorter one. I had already developed a similar service called wittylink.com, which is still operating, but I needed a shorter domain name and wanted to add new features, so I created kiq.me.

This new service has two features: it is twitter aware, and your urls are encoded into Data Matrix barcodes.

  • Twitter. When you encode your URL, kiq.me allows you to directly post the newly encoded URL and a message on twitter. You don’t have to cut and paste or copy the new url to your twitter page. Just check the box post this url on twitter, type your account information and message and “voila” the new short url is posted on twitter. For example the URL to this article is encoded into http://kiq.me/S

  • Barcode. Your new short url is also encoded into a Data Matrix barcode. You can print this barcode in your organization’s newsletter, on a poster, on an ad, on your business card, send it by email, or put the image on your website. This allows every user of a phone with a camera and a web browser to take a picture of this barcode and to be automatically routed to your web site.
    There are plenty of bar code readers for cellphones. For example, you can search the iPhone App Store for beetagg reader, neoreader, or upcode. I like upcode, it is light and does a good job.

So please give kiq.me a try and let me know what you think. I’m considering adding interfaces to other services. I’d like to know if this is useful to you first.

 
Posted on Dec 01, 2008 by: Fred Cirera @ 15:34 Leave a comment Comments: 22

Nice looking elapsed time with SQLAlchemy

http://fred.velvnet.com/python-logo.png
In your relational database, the date and time are usually stored as a DateTime field, because it is more convenient for sorting, search and dates calculation. But when displayed these fields don't look very nice. Often on popular web sites the date of an article is displayed like this «about a hour ago». The following function shows you how to display human readable elapsed times.

 
Posted on Nov 07, 2008 by: Fred Cirera @ 12:01 Leave a comment Comments: 19

Python code to check your Google PageRank

The Google PageRank is a numeric value that represents how important your page is on the web. It is based on the number and quality of "backlinks" a webpage has. A high PageRank indicates that the page must be important since many sites are linking to it.

 
Posted on Aug 28, 2008 by: Fred Cirera @ 18:09 Leave a comment Comments: 38

Send a multipart email in Python

This short example show how to send a mail with attachments using Python.
First we create a Mime container using the class MimeWriter and then the message is sent using smtplib package.

 
Posted on Jan 24, 2008 by: Fred Cirera @ 13:28 Leave a comment Comments: 28

Print human readable file size.

Often you have to print a file or a directory size. Here is a small recipe to print a file, or a directory size easily readable by humans.

def sizeof_fmt(num):
    for x in ['bytes','KB','MB','GB','TB']:
        if num < 1024.0:
            return "%3.1f%s" % (num, x)
        num /= 1024.0

def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB','TB']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0

Example:
>>> sizeof_fmt(168963795964)
'157.4GB'

>>> sizeof_fmt(168963795964)
'157.4GB'
 
Posted on Dec 12, 2007 by: Fred Cirera @ 19:22 Leave a comment Comments: 16