1 diff -ru a/weather b/weather
2 --- a/weather 2010-10-29 02:38:04.000000000 +0000
3 +++ b/weather 2010-10-29 02:23:10.000000000 +0000
5 get_bool = selections.get_bool
7 # this mode just lists the aliases defined in the config
8 -if get_bool("list"): print weather.list_aliases(selections.config)
9 +if get_bool("list"): print( weather.list_aliases(selections.config) )
13 diff -ru a/weather.py b/weather.py
14 --- a/weather.py 2010-10-29 02:37:59.000000000 +0000
15 +++ b/weather.py 2010-10-29 02:43:13.000000000 +0000
20 +def pyversion(ref=None):
21 + """Determine the Python version and optionally compare to a reference."""
23 + ver = platform.python_version()
26 + int(x) for x in ver.split(".")
28 + int(x) for x in ref.split(".")
33 """An object to contain selection data."""
37 def get_url(url, ignore_fail=False):
38 """Return a string containing the results of a URL GET."""
40 - try: return urllib2.urlopen(url).read()
41 - except urllib2.URLError:
43 + import urllib.error, urllib.request
44 + URLError = urllib.error.URLError
45 + urlopen = urllib.request.urlopen
47 + import urllib2 as urllib
48 + URLError = urllib.URLError
49 + urlopen = urllib.urlopen
50 + try: return urlopen(url).read()
52 if ignore_fail: return ""
56 murl = murl.replace("%id%", id.lower())
57 murl = murl.replace(" ", "_")
59 + if pyversion("3") and type(metar) is bytes: metar = metar.decode("utf-8")
60 if verbose: return metar
62 lines = metar.split("\n")
64 aurl = aurl.replace("%zone%", zone.lower())
65 aurl = aurl.replace(" ", "_")
66 alert = get_url(aurl, ignore_fail=True).strip()
67 + if pyversion("3") and type(alert) is bytes: alert = alert.decode("utf-8")
69 if verbose: return alert
72 furl = furl.replace("%st%", st.lower())
73 furl = furl.replace(" ", "_")
74 forecast = get_url(furl)
75 + if pyversion("3") and type(forecast) is bytes:
76 + forecast = forecast.decode("utf-8")
77 if verbose: return forecast
79 lines = forecast.split("\n")
83 """Parse the aliases and configuration."""
85 - config = ConfigParser.ConfigParser()
87 + if pyversion("3"): import configparser
88 + else: import ConfigParser as configparser
89 + config = configparser.ConfigParser()