changeset 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 2a83052a7a50
children 13055811fd0b
files python/tld.py
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
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))