Mercurial > hg > config
comparison 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 |
comparison
equal
deleted
inserted
replaced
116:2a83052a7a50 | 117:c7edd15d7f8b |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 URL = 'http://www.palosverdes.com/jesse/irc/country.txt' | |
4 | |
5 import urllib2 | |
6 | |
7 def codes(): | |
8 f = urllib2.urlopen(URL) | |
9 codes = {} | |
10 for line in f.readlines(): | |
11 line = line.strip() | |
12 if not line: | |
13 continue | |
14 key, value = line.split(None, 1) | |
15 codes[key.lower()] = value | |
16 return codes | |
17 codes = codes() | |
18 | |
19 def get(code): | |
20 code = code.lstrip('.').lower() | |
21 return codes.get(code) | |
22 | |
23 if __name__ == '__main__': | |
24 import sys | |
25 for arg in sys.argv[1:]: | |
26 print '%s: %s' % (arg, get(arg)) |