# 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() self.ids.tides_label.text = '\n'.join([tide.text for tide in tides]) 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" # Get the data from the API response = requests.get(url) # 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