Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/wavewatch/api/data_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,19 @@ def get_current_conditions(self, beach_name: str, lat: Optional[float] = None, l
Returns:
Dictionary with current conditions
"""
current_hour_index = datetime.now().hour
result = self.fetch_surf_data(beach_name, lat, lng, target_date)

if 'error' in result:
return result

try:
data = result['data']
current_hour = data['hours'][0] # Get current hour data

try:
current_hour = data['hours'][current_hour_index]
except IndexError:
current_hour = data['hours'][0] # Default to first hour (00:00) if index is out of range

# Convert units from metric to imperial
wave_height_m = current_hour.get('waveHeight', {}).get('noaa', 'N/A')
wave_height_ft = round(float(wave_height_m) * 3.28084, 1) if wave_height_m != 'N/A' else 'N/A'
Expand Down