Caching support for URLs with port numbers
[weather.git] / weather.py
index 78fd79c..71cf0ec 100644 (file)
@@ -212,7 +212,7 @@ def get_uri(
             except (IOError, OSError): pass
         dcache_fn = os.path.join(
             dcachedir,
-            uri.split(":")[1].replace("/","_")
+            uri.split(":",1)[1].replace("/","_")
         )
     now = time.time()
     if cache_data and os.access(dcache_fn, os.R_OK) \
@@ -222,8 +222,7 @@ def get_uri(
         dcache_fd.close()
     else:
         try:
-            if pyversion("3"): data = urlopen(uri).read().decode("utf-8")
-            else: data = urlopen(uri).read()
+            data = urlopen(uri).read().decode("utf-8")
         except URLError:
             if ignore_fail: return ""
             else:
@@ -238,6 +237,9 @@ def get_uri(
                     )
                 sys.stderr.write(message)
                 sys.exit(1)
+        # Some data sources are HTML with the plain text wrapped in pre tags
+        if "<pre>" in data:
+            data = data[data.find("<pre>")+5:data.find("</pre>")]
         if cache_data:
             try:
                 import codecs
@@ -1132,7 +1134,7 @@ def guess(
         )
         search_cache = ["\n"]
         search_cache.append( "[%s]\n" % search[0] ) 
-        search_cache.append( "description = cached %s\n" % nowstamp )
+        search_cache.append( "cached = %s\n" % nowstamp )
         for uriname in sorted(uris.keys()):
             search_cache.append( "%s = %s\n" % ( uriname, uris[uriname] ) )
         real_cachedir = os.path.expanduser(cachedir)