Check If Yahoo! ID Is Online Or Not Using Python

Now is almost 1 PM, and I still cannot sleep. Suddenly I get the idea to write something in Python: a script to check whether a Yahoo! ID is online or not.

The basic principle is to use this Yahoo! API:<Yahoo! ID>

Now let’s say your Yahoo! ID is john.doe. Open this URL in your browser:

If that ID is online, you’ll see this picture:

Otherwise, you’ll see this:

To sum it up, this is the algo:

  1. Call the URL, and save the result as a file.
  2. Calculate the MD5 sum of the file (of course you are not limited to MD5, you can use any checksum algo)
  3. See the ‘online’ image above? It’s MD5 sum is 9e31b63daa88647ead982d2c7598e634. Now calculate the MD5 sum of the saved file. If both MD5 sums are match, it means that the Yahoo! ID is online. Otherwise, it’s offline.
And this is the Python script.


# A simple script to check whether a Yahoo! ID is online or not
# Usage: python2
# Example: python2 john.doe

import pycurl
import StringIO
import md5
import sys

ONLINE_VALUE = '9e31b63daa88647ead982d2c7598e634'
buffer = StringIO.StringIO()

# Call the API via curl
# and save the result into file called 'img'
user = sys.argv[1]
curl = pycurl.Curl()
curl.setopt(curl.URL, ''+user)
curl.setopt(curl.WRITEFUNCTION, buffer.write)
tmpfile = open('img', 'wb')

# Calculate the MD5 of 'img'
tmpfile = open('img','rb')
md5_result =

# Compare it with the predefined value above
if (md5_result == ONLINE_VALUE):
 print'%s is online' % (user)
 print '%s is offline' % (user)

P.S: I make NO claims that the above code is robust/efficient/etc. It’s just a quick n’ dirty script, anyway :mrgreen:

BTW, the above code is only tested with Python 2, because the pycurl available in the GNU/Linux distro I’m using is not compatible with Python 3.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s