1111from src import api , art
1212from src .gpt import get_llm_client
1313
14-
1514logger = logging .getLogger (__name__ )
1615
1716MAX_FORECAST_DAYS = 7
@@ -245,7 +244,7 @@ def print_ocean_data(arguments_dict, ocean_data_dict):
245244 ]
246245
247246 for arg_key , data_key , label in mappings :
248- if arguments_dict [ arg_key ] :
247+ if arguments_dict . get ( arg_key ) and data_key in ocean_data_dict :
249248 print (f"{ label } { ocean_data_dict [data_key ]} " )
250249
251250 if arguments_dict .get ("show_tide" ) and ocean_data_dict .get ("Tide" ):
@@ -257,8 +256,13 @@ def print_ocean_data(arguments_dict, ocean_data_dict):
257256 arrow = f"{ color } { arrow } { art .colors ['end' ]} "
258257 extreme = tide ["next_extreme" ]
259258 extreme_type = "High" if extreme ["type" ] == "H" else "Low"
260- extreme_time = datetime .fromisoformat (extreme ["time" ]).strftime ("%H:%M UTC" )
261- print (f"Tide: { tide ['height_ft' ]} ft { arrow } | Next { extreme_type } : { extreme ['height' ]:.2f} ft @ { extreme_time } " )
259+ extreme_time = datetime .fromisoformat (extreme ["time" ]).strftime (
260+ "%H:%M UTC"
261+ )
262+ print (
263+ f"Tide: { tide ['height_ft' ]} ft { arrow } | "
264+ f"Next { extreme_type } : { extreme ['height' ]:.2f} ft @ { extreme_time } "
265+ )
262266
263267
264268def print_forecast (ocean , forecast ):
@@ -411,15 +415,21 @@ def get_gpt_response(surf_data):
411415 tide = surf_data ["Tide" ]
412416 extreme = tide ["next_extreme" ]
413417 extreme_type = "high" if extreme ["type" ] == "H" else "low"
414- extreme_time = datetime .fromisoformat (extreme ["time" ]).strftime ("%H:%M UTC" )
418+ extreme_time = datetime .fromisoformat (extreme ["time" ]).strftime (
419+ "%H:%M UTC"
420+ )
415421 tide_desc = (
416- f" The tide is currently { tide ['direction' ]} at { tide ['height_ft' ]} ft,"
417- f" with the next { extreme_type } tide of { extreme ['height' ]:.2f} ft at { extreme_time } ."
422+ f" The tide is currently { tide ['direction' ]} at"
423+ f" { tide ['height_ft' ]} ft, with the next { extreme_type } tide"
424+ f" of { extreme ['height' ]:.2f} ft at { extreme_time } ."
418425 )
419426
420427 sea_temp_desc = ""
421428 if surf_data .get ("Sea Surface Temperature" ) is not None :
422- sea_temp_desc = f" The sea surface temperature is { surf_data ['Sea Surface Temperature' ]} { unit_label } ."
429+ sea_temp_desc = (
430+ f" The sea surface temperature is"
431+ f" { surf_data ['Sea Surface Temperature' ]} { unit_label } ."
432+ )
423433
424434 summary = (
425435 f"Today at { surf_data ['Location' ]} , the surf height is "
@@ -434,19 +444,22 @@ def get_gpt_response(surf_data):
434444 logger .error ("LLM request failed: %s" , e )
435445 return "Unable to generate GPT response."
436446
447+
437448def current_tide (lat : float , long : float ) -> dict :
438449 predictions = api .get_tide_data (lat , long )["predictions" ]
439450
440451 parsed = [
441452 {
442- "time" : datetime .strptime (p ["t" ], "%Y-%m-%d %H:%M" ).replace (tzinfo = timezone .utc ),
453+ "time" : datetime .strptime (p ["t" ], "%Y-%m-%d %H:%M" ).replace (
454+ tzinfo = timezone .utc
455+ ),
443456 "height" : float (p ["v" ]),
444457 "type" : p ["type" ],
445458 }
446459 for p in predictions
447460 ]
448461
449- now = datetime .now (timezone .utc ) # ← tz-aware UTC
462+ now = datetime .now (timezone .utc ) # ← tz-aware UTC
450463
451464 prev = next_ = None
452465 for a , b in zip (parsed , parsed [1 :]):
@@ -460,7 +473,8 @@ def current_tide(lat: float, long: float) -> dict:
460473 span = (next_ ["time" ] - prev ["time" ]).total_seconds ()
461474 elapsed = (now - prev ["time" ]).total_seconds ()
462475 x = elapsed / span
463- height = prev ["height" ] + (next_ ["height" ] - prev ["height" ]) * (1 - cos (pi * x )) / 2
476+ delta = next_ ["height" ] - prev ["height" ]
477+ height = prev ["height" ] + delta * (1 - cos (pi * x )) / 2
464478
465479 direction = "incoming" if next_ ["type" ] == "H" else "outgoing"
466480
@@ -475,6 +489,5 @@ def current_tide(lat: float, long: float) -> dict:
475489 }
476490
477491
478-
479492if __name__ == "__main__" :
480- print (current_tide (32.856132 , - 117.2175761 ))
493+ print (current_tide (32.856132 , - 117.2175761 ))
0 commit comments