
import urllib2, re, time
import iemdb
MESOSITE = iemdb.connect('mesosite')
mcursor = MESOSITE.cursor()
mcursor2 = MESOSITE.cursor()

mcursor.execute("""
 SELECT network, x(geom) as lon, y(geom) as lat, elevation, id from stations 
 WHERE (elevation < -990 or elevation is null)""")

for row in mcursor:
  elev = row[3]
  lat = row[2]
  lon = row[1]
  id = row[4]
  network = row[0]
  r = urllib2.urlopen('http://weather.gladstonefamily.net/cgi-bin/wx-get-elevation.pl?lat=%s&lng=%s' % (lat,lon)).read()
  tokens =  re.findall(' ele="([0-9\.\-]*)" ', r)
  if len(tokens) == 0:
    print 'ERROR WITH ', id, r
    continue
  newelev = float(tokens[0])

  print "%7s %s OLD: %s NEW: %.3f" % (id, network, elev, newelev)
  mcursor2.execute("UPDATE stations SET elevation = %s WHERE id = '%s' and network = '%s'" % (newelev, id, network))
  time.sleep(2)

mcursor2.close()
MESOSITE.commit()

@@ -32,16 +32,34 @@
 t iemdb%0A
+import simplejson%0A
 MESOSITE
@@ -396,16 +396,17 @@
 ow%5B0%5D%0A  
+#
 r = urll
@@ -518,16 +518,241 @@
 ead()%0A  
+r = urllib2.urlopen('http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationAtLonLat?lon=%25s&lat=%25s&f=pjson' %25 (lon,lat)).read()%0A  #
 tokens =
@@ -793,16 +793,17 @@
 ', r)%0A  
+#
 if len(t
@@ -817,16 +817,17 @@
 == 0:%0A  
+#
   print 
@@ -842,19 +842,57 @@
 ITH 
-', id, r
+%25s La: %25s Lo: %25s Res: %25s' %25 (id, lat, lon, r)
 %0A  
+#
   co
@@ -900,16 +900,17 @@
 tinue%0A  
+#
 newelev 
@@ -927,16 +927,75 @@
 kens%5B0%5D)
+%0A  json = simplejson.loads(r)%0A  newelev = json%5B'elevation'%5D
 %0A%0A  prin

Use ArcGIS elevation service, which does not see to fail for places like Namibia