# customPanels.py # Load required modules from kivy.uix.relativelayout import RelativeLayout from kivy.clock import Clock from panels.template import panelTemplate import requests import xml.etree.ElementTree as ET # ============================================================================== # Tides CUSTOM PANEL # ============================================================================== class TidesPanel(panelTemplate): def __init__(self, **kwargs): super().__init__(**kwargs) self.update_tides() def update_tides(self, *args): tides = get_tides() tides_str = '\n'.join(["{}: {}".format(tide.attrib['t'], tide.attrib['v']) for tide in tides]) self.ids.tides_label.text = tides_str class TidesButton(RelativeLayout): pass # Function to parse the tides data from the API def get_tides(): # API URL url = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?date=today&range=48&station=8466791&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=xml" try: # Get the data from the API response = requests.get(url) # Check if the API request was successful if response.status_code != 200: raise Exception(f"API request failed with status code: {response.status_code}") print(response.text) # Parse the data from the API root = ET.fromstring(response.text) # Get the tides information tides = root.findall("./data/item/t") # Return the tides information return tides except Exception as e: # Log the error message print(f"Error getting tides data: {e}") return []