-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #580 from akrherz/231107-2
mnt: expand SCAN processing
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Pull in what NRCS has for stations.""" | ||
|
||
import requests | ||
from pyiem.database import get_dbconnc | ||
from pyiem.network import Table as NetworkTable | ||
from pyiem.util import convert_value | ||
|
||
|
||
def main(): | ||
"""Go Main Go.""" | ||
mesosite, mcursor = get_dbconnc("mesosite") | ||
nt = NetworkTable("SCAN", only_online=False) | ||
entries = requests.get( | ||
"https://wcc.sc.egov.usda.gov/awdbRestApi/services/v1/stations?" | ||
"activeOnly=true&returnForecastPointMetadata=false&" | ||
"returnReservoirMetadata=false&returnStationElements=false", | ||
timeout=30, | ||
).json() | ||
for meta in entries: | ||
if meta["networkCode"] != "SCAN": | ||
continue | ||
station = f"S{int(meta['stationId']):04d}" | ||
if station in nt.sts: | ||
continue | ||
print(f"Adding {station} {meta['name']}") | ||
mcursor.execute( | ||
"INSERT into stations(id, name, network, online, country, " | ||
"state, plot_name, elevation, metasite, geom) " | ||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, " | ||
"ST_Point(%s, %s, 4326))", | ||
( | ||
station, | ||
meta["name"], | ||
"SCAN", | ||
"t", | ||
"US", | ||
meta["stateCode"], | ||
meta["name"], | ||
convert_value(meta["elevation"], "foot", "meter"), | ||
"f", | ||
meta["longitude"], | ||
meta["latitude"], | ||
), | ||
) | ||
mcursor.close() | ||
mesosite.commit() | ||
mesosite.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
File renamed without changes.