Update USGS Water Levels app with new API and richer river options. - #583
Conversation
Migrate to the modern USGS Water Data API, add custom display names, expand river parameters, and filter the parameter picker by water body type. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request updates the USGS water levels app to use the OGC API continuous features endpoint, adds support for custom display names, and dynamically generates parameter options based on the water body type. Feedback highlights that bypassing the cache to fetch fresh data on every execution defeats the purpose of caching and may cause rate-limiting. Additionally, potential runtime errors could occur if the properties field in the JSON response is null, as calling .get() on a None value will fail.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| # Get fresh data, falling back to cache only when the fetch fails | ||
| cache_key = "usgs_data_" + site_id + "_" + water_body_type + "_" + param_code | ||
| cached_data = cache.get(cache_key) | ||
|
|
||
| if cached_data != None: | ||
| data = fetch_usgs_data(site_id, water_body_type, param_code) | ||
| if data: | ||
| cache.set(cache_key, json.encode(data), ttl_seconds = CACHE_TTL_SECONDS) | ||
| elif cached_data != None: | ||
| data = json.decode(cached_data) |
There was a problem hiding this comment.
Bypassing the cache on every execution to fetch fresh data defeats the purpose of caching and will cause rate-limiting or timeouts. Check the cache first.
| # Get fresh data, falling back to cache only when the fetch fails | |
| cache_key = "usgs_data_" + site_id + "_" + water_body_type + "_" + param_code | |
| cached_data = cache.get(cache_key) | |
| if cached_data != None: | |
| data = fetch_usgs_data(site_id, water_body_type, param_code) | |
| if data: | |
| cache.set(cache_key, json.encode(data), ttl_seconds = CACHE_TTL_SECONDS) | |
| elif cached_data != None: | |
| data = json.decode(cached_data) | |
| # Get cached data or fetch new data | |
| cache_key = "usgs_data_" + site_id + "_" + water_body_type + "_" + param_code | |
| cached_data = cache.get(cache_key) | |
| if cached_data != None: | |
| data = json.decode(cached_data) | |
| else: | |
| data = fetch_usgs_data(site_id, water_body_type, param_code) | |
| if data: | |
| cache.set(cache_key, json.encode(data), ttl_seconds = CACHE_TTL_SECONDS) |
| start_str_30d = start_date_30d.format("2006-01-02") | ||
| start_str_current = start_date_current.format("2006-01-02") | ||
| end_str = end_date.format("2006-01-02") | ||
| props = resp.json().get("properties", {}) |
There was a problem hiding this comment.
| values_current = time_series_current["values"][0]["value"] | ||
| processed_values = [] | ||
| for feature in features: | ||
| val_str = feature.get("properties", {}).get("value") |
Migrate to the modern USGS Water Data API, add custom display names, expand river parameters, and filter the parameter picker by water body type.