Skip to content

Update USGS Water Levels app with new API and richer river options. - #583

Merged
tavdog merged 2 commits into
mainfrom
usgs-water-levels-improvements
Jul 8, 2026
Merged

Update USGS Water Levels app with new API and richer river options.#583
tavdog merged 2 commits into
mainfrom
usgs-water-levels-improvements

Conversation

@tavdog

@tavdog tavdog commented Jul 8, 2026

Copy link
Copy Markdown
Member

Migrate to the modern USGS Water Data API, add custom display names, expand river parameters, and filter the parameter picker by water body type.

tavdog and others added 2 commits July 8, 2026 12:18
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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +24 to 31
# 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
# 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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relying on http cache.

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", {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the properties field is null in the JSON response, get("properties", {}) returns None, causing a runtime error when calling .get(). Use or {} to handle null values safely.

Suggested change
props = resp.json().get("properties", {})
props = resp.json().get("properties") or {}

values_current = time_series_current["values"][0]["value"]
processed_values = []
for feature in features:
val_str = feature.get("properties", {}).get("value")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the properties field is null in the JSON response, get("properties", {}) returns None, causing a runtime error when calling .get(). Use or {} to handle null values safely.

            props = feature.get("properties") or {}
            val_str = props.get("value")

@tavdog
tavdog merged commit 7cb6bdc into main Jul 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant