Skip to content

Commit a35944e

Browse files
GCluniesclaude
andcommitted
fix(examples): use a dynamic date window for currents demos
NOAA no longer returns currents data for the hardcoded 20210414-15 window at station s09010, so demo_currents and currents_example.py crashed with a "No data was found" COOPSAPIError. Compute a two-day UTC window ending yesterday so the demos stay fresh against NOAA's rolling real-time availability. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 893a17b commit a35944e

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

examples/currents_example.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
from datetime import datetime, timedelta, timezone
2+
13
import noaa_coops as nc
24

5+
# Use a two-day window ending yesterday (UTC) so this example stays fresh
6+
# against NOAA's rolling real-time currents availability.
7+
end = datetime.now(timezone.utc).date() - timedelta(days=1)
8+
begin = end - timedelta(days=1)
39

410
oakland_outer_LB3 = nc.Station("s09010")
511
currents = oakland_outer_LB3.get_data(
6-
begin_date="20210414",
7-
end_date="20210415",
12+
begin_date=begin.strftime("%Y%m%d"),
13+
end_date=end.strftime("%Y%m%d"),
814
product="currents",
915
bin_num=2,
1016
units="metric",

examples/readme_demo.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# attributes at runtime, so static attribute checks don't apply here.
1212
# pyright: reportAttributeAccessIssue=false
1313

14+
from datetime import datetime, timedelta, timezone
1415
from pprint import pprint
1516

1617
from noaa_coops import Station, get_stations_from_bbox
@@ -74,10 +75,14 @@ def demo_get_data(seattle: Station) -> None:
7475

7576
def demo_currents() -> None:
7677
section("6. get_data — Oakland currents (examples/currents_example.py)")
78+
# Use a two-day window ending yesterday (UTC) so the demo stays fresh
79+
# against NOAA's rolling real-time currents availability.
80+
end = datetime.now(timezone.utc).date() - timedelta(days=1)
81+
begin = end - timedelta(days=1)
7782
station = Station("s09010")
7883
df = station.get_data(
79-
begin_date="20210414",
80-
end_date="20210415",
84+
begin_date=begin.strftime("%Y%m%d"),
85+
end_date=end.strftime("%Y%m%d"),
8186
product="currents",
8287
bin_num=2,
8388
units="metric",

0 commit comments

Comments
 (0)