import colors import requests from configparser import ConfigParser class WeatherDisplay: def __init__(self, characterDisplay, topRow, configFile): self.characterDisplay = characterDisplay self.topRow = topRow self.currentTemperature = [9, 9] self.currentColor = colors.BLACK self.color = colors.BLUE config = ConfigParser() config.read(configFile) self.host = config['weather'].get('host') self.user = config['weather'].get('user') self.password = config['weather'].get('pass') self.lat = config['weather'].get('lat') self.lon = config['weather'].get('lon') print(self.host) def showWeather(self): self.showTemperature(self.getTemperatureCharacters(self.getTemperature())) def showTemperature(self, temperature): start = 6 for c in temperature: if c == '-': self.characterDisplay.displayNegative(start, self.topRow, self.color) start = start + 3 else: self.characterDisplay.displayDigit(start, self.topRow, c, self.color) start = start + 4 def getTemperature(self): return list(filter(lambda t: t["timestep"] == 'current', requests.get(f'https://{self.host}/api/weather?lat={self.lat}&lon={self.lon}&units=metric', auth=(self.user, self.password)).json()["tomorrow"]["data"]['timelines']))[0]["intervals"][0]["values"]["temperature"] def getTemperatureCharacters(self, temperature): return list(str(round(temperature)))