Mercurial > hg > config
diff python/tld.py @ 117:c7edd15d7f8b
add a function to get a TLD from a webservice
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 14 Dec 2010 10:31:09 -0800 |
parents | |
children | 0bc7c1a5eb83 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/tld.py Tue Dec 14 10:31:09 2010 -0800 @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +URL = 'http://www.palosverdes.com/jesse/irc/country.txt' + +import urllib2 + +def codes(): + f = urllib2.urlopen(URL) + codes = {} + for line in f.readlines(): + line = line.strip() + if not line: + continue + key, value = line.split(None, 1) + codes[key.lower()] = value + return codes +codes = codes() + +def get(code): + code = code.lstrip('.').lower() + return codes.get(code) + +if __name__ == '__main__': + import sys + for arg in sys.argv[1:]: + print '%s: %s' % (arg, get(arg))