]> git.phdru.name Git - IM.git/blob - icq-status.py
Ignore error if skype is not running
[IM.git] / icq-status.py
1 #! /usr/bin/env python
2
3 import sys
4
5 try:
6     uin = sys.argv[1]
7 except IndexError:
8     sys.exit("Usage: %s uin" % sys.argv[0])
9
10 url = "http://status.icq.com/online.gif?icq=%s&img=1" % uin
11
12 import socket
13 socket.setdefaulttimeout(30)
14
15 import urllib
16 protocol, request = urllib.splittype(url)
17 host, path = urllib.splithost(request)
18 host, port = urllib.splitport(host)
19 path, tag  = urllib.splittag(path)
20
21 import httplib
22 server = httplib.HTTP(host, port)
23
24 server.putrequest("HEAD", path)
25 server.putheader("Host", host)
26 server.endheaders()
27
28 status, reason, msg = server.getreply()
29 if status == 302:
30    online = msg["Location"]
31 else:
32    print >>sys.stderr, status, reason, msg
33    sys.exit(1)
34
35 # Classify online status
36 if online == "/1/online0.gif":
37    print "Offline"
38 elif online == "/1/online1.gif":
39    print "Online"
40 elif online == "/1/online2.gif":
41    print "Unknown/invisible"
42 else:
43    print >>sys.stderr, "Unknown status", online
44    sys.exit(1)