def main(): """Go Main""" dbconn = get_dbconn('mesosite', user='******') cursor = dbconn.cursor() cursor.execute(""" SELECT id, state, country, network from stations WHERE network ~* 'DCP' and length(id) = 5""") for row in cursor: nwsli = row[0] state = row[1] country = row[2] network = row[3] code = nwsli[-2:] country2 = nwsli2country.get(code) if country != country2: print(("ID:%s ST:%s C:%s NET:%s L_C:%s") % (nwsli, state, country, network, country2)) network2 = "%s_DCP" % (state, ) if country in ["MX", "CA"]: network2 = "%s_%s_DCP" % (country, state) elif country not in ["MX", "CA", "US"]: network2 = "%s__DCP" % (country, ) if network != network2: print(("ID:%s ST:%s C:%s NET:%s L_N:%s") % (nwsli, state, country, network, network2)) state2 = nwsli2state.get(code) if state is not None and state != state2: print(("ID:%s ST:%s C:%s NET:%s L_S:%s") % (nwsli, state, country, network, state2))
def main(): """Go Main Go""" fh = open("insert.sql", "w") req = requests.get("http://www.weather.gov/source/aprfc/nrcs_swe.json") j = req.json() for feature in j["features"]: nwsli = feature["properties"]["lid"] name = feature["properties"]["name"] elev = distance(float(feature["properties"]["elev"]), "FT").value("M") lon, lat = feature["geometry"]["coordinates"] country = nwsli2country.get(nwsli[3:]) state = nwsli2state.get(nwsli[3:]) network = "%s_DCP" % (state, ) sql = """INSERT into stations(id, name, network, country, state, plot_name, elevation, online, metasite, geom) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %s, 't', 'f', 'SRID=4326;POINT(%s %s)'); """ % ( nwsli, name, network, country, state, name, float(elev), float(lon), float(lat), ) fh.write(sql) fh.close()
def compute_network(nwsli): country = nwsli2country.get(nwsli[3:]) state = nwsli2state.get(nwsli[3:]) if country == "US" and state is not None: return "US", state, "%s_DCP" % (state,) if country != "US" and state is not None: return country, state, "%s_%s_DCP" % (country, state) print(("Failure to compute state for nwsli: %s [country:%s, state:%s]") % (nwsli, country, state)) return None, None, None
def compute_network(nwsli): country = nwsli2country.get(nwsli[3:]) state = nwsli2state.get(nwsli[3:]) if country == 'US' and state is not None: return "US", state, "%s_DCP" % (state,) if country != 'US' and state is not None: return country, state, "%s_%s_DCP" % (country, state) print(("Failure to compute state for nwsli: %s [country:%s, state:%s]" ) % (nwsli, country, state)) return None, None, None
def compute_network(nwsli): """Figure out the IEM network based on a NWSLI""" country = nwsli2country.get(nwsli[3:]) state = nwsli2state.get(nwsli[3:]) if country == "US" and state is not None: return "US", state, "%s_DCP" % (state, ) if country != "US" and state is not None: return country, state, "%s_%s_DCP" % (country, state) print(("Failure to compute state for nwsli: %s [country:%s, state:%s]") % (nwsli, country, state)) return None, None, None
def main(): """Go Main Go""" fh = open('insert.sql', 'w') req = requests.get('http://www.weather.gov/source/aprfc/nrcs_swe.json') j = req.json() for feature in j['features']: nwsli = feature['properties']['lid'] name = feature['properties']['name'] elev = distance(float(feature['properties']['elev']), 'FT').value('M') lon, lat = feature['geometry']['coordinates'] country = nwsli2country.get(nwsli[3:]) state = nwsli2state.get(nwsli[3:]) network = "%s_DCP" % (state, ) sql = """INSERT into stations(id, name, network, country, state, plot_name, elevation, online, metasite, geom) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %s, 't', 'f', 'SRID=4326;POINT(%s %s)'); """ % (nwsli, name, network, country, state, name, float(elev), float(lon), float(lat)) fh.write(sql) fh.close()
dbconn = psycopg2.connect(database='mesosite', host='iemdb', user='******') cursor = dbconn.cursor() cursor.execute(""" SELECT id, state, country, network from stations WHERE network ~* 'DCP' and length(id) = 5""") for row in cursor: nwsli = row[0] state = row[1] country = row[2] network = row[3] code = nwsli[-2:] country2 = nwsli2country.get(code) if country != country2: print "ID:%s ST:%s C:%s NET:%s L_C:%s" % (nwsli, state, country, network, country2) network2 = "%s_DCP" % (state, ) if country in ["MX", "CA"]: network2 = "%s_%s_DCP" % (country, state) elif country not in ["MX", "CA", "US"]: network2 = "%s__DCP" % (country, ) if network != network2: print "ID:%s ST:%s C:%s NET:%s L_N:%s" % (nwsli, state, country, network, network2) state2 = nwsli2state.get(code) if state is not None and state != state2: print "ID:%s ST:%s C:%s NET:%s L_S:%s" % (nwsli, state, country,
import requests from pyiem.reference import nwsli2country, nwsli2state from pyiem.datatypes import distance OUTPUT = open('insert.sql', 'w') req = requests.get('http://www.weather.gov/source/aprfc/nrcs_swe.json') j = req.json() for feature in j['features']: nwsli = feature['properties']['lid'] name = feature['properties']['name'] elev = distance(float(feature['properties']['elev']), 'FT').value('M') lon, lat = feature['geometry']['coordinates'] country = nwsli2country.get(nwsli[3:]) state = nwsli2state.get(nwsli[3:]) network = "%s_DCP" % (state, ) sql = """INSERT into stations(id, name, network, country, state, plot_name, elevation, online, metasite, geom) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %s, 't', 'f', 'SRID=4326;POINT(%s %s)'); """ % (nwsli, name, network, country, state, name, float(elev), float(lon), float(lat)) OUTPUT.write(sql) OUTPUT.close()
import requests from pyiem.reference import nwsli2country, nwsli2state from pyiem.datatypes import distance OUTPUT = open("insert.sql", "w") req = requests.get("http://www.weather.gov/source/aprfc/nrcs_swe.json") j = req.json() for feature in j["features"]: nwsli = feature["properties"]["lid"] name = feature["properties"]["name"] elev = distance(float(feature["properties"]["elev"]), "FT").value("M") lon, lat = feature["geometry"]["coordinates"] country = nwsli2country.get(nwsli[3:]) state = nwsli2state.get(nwsli[3:]) network = "%s_DCP" % (state,) sql = """INSERT into stations(id, name, network, country, state, plot_name, elevation, online, metasite, geom) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %s, 't', 'f', 'SRID=4326;POINT(%s %s)'); """ % ( nwsli, name, network, country, state, name, float(elev), float(lon), float(lat), )
dbconn = psycopg2.connect(database='mesosite', host='iemdb', user='******') cursor = dbconn.cursor() cursor.execute(""" SELECT id, state, country, network from stations WHERE network ~* 'DCP' and length(id) = 5""") for row in cursor: nwsli = row[0] state = row[1] country = row[2] network = row[3] code = nwsli[-2:] country2 = nwsli2country.get(code) if country != country2: print "ID:%s ST:%s C:%s NET:%s L_C:%s" % (nwsli, state, country, network, country2) network2 = "%s_DCP" % (state, ) if country in ["MX", "CA"]: network2 = "%s_%s_DCP" % (country, state) elif country not in ["MX", "CA", "US"]: network2 = "%s__DCP" % (country,) if network != network2: print "ID:%s ST:%s C:%s NET:%s L_N:%s" % (nwsli, state, country, network, network2) state2 = nwsli2state.get(code) if state is not None and state != state2: print "ID:%s ST:%s C:%s NET:%s L_S:%s" % (nwsli, state, country,