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:
Now let’s say your Yahoo! ID is john.doe. Open this URL in your browser:
To sum it up, this is the algo:
- Call the URL, and save the result as a file.
- Calculate the MD5 sum of the file (of course you are not limited to MD5, you can use any checksum algo)
- 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.
#!/usr/bin/python2 # A simple script to check whether a Yahoo! ID is online or not # Usage: python2 ycheck.py # Example: python2 ycheck.py 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 curl = pycurl.Curl() curl.setopt(curl.URL, 'http://presence.msg.yahoo.com/online?u='+user) curl.setopt(curl.WRITEFUNCTION, buffer.write) curl.perform() tmpfile = open('img', 'wb') tmpfile.write(buffer.getvalue()) tmpfile.close() # Calculate the MD5 of 'img' tmpfile = open('img','rb') md5_result = md5.new(tmpfile.read()).hexdigest() tmpfile.close() # Compare it with the predefined value above if (md5_result == ONLINE_VALUE): print'%s is online' % (user) else: 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
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.