diff --git a/character_display.py b/character_display.py index e7cc9ac..ad51236 100644 --- a/character_display.py +++ b/character_display.py @@ -25,16 +25,6 @@ class CharacterDisplay: self.maxX = maxX self.digits = { - 0: self.displayZero, - 1: self.displayOne, - 2: self.displayTwo, - 3: self.displayThree, - 4: self.displayFour, - 5: self.displayFive, - 6: self.displaySix, - 7: self.displaySeven, - 8: self.displayEight, - 9: self.displayNine, '0': self.displayZero, '1': self.displayOne, '2': self.displayTwo, @@ -66,7 +56,7 @@ class CharacterDisplay: self.unicorn.show() - def displayTimeDots(self, x, y, color): + def displayTimeDots(self, x, y, color,): self.setPixel(x, y, colors.BLACK) self.setPixel(x, y-1, color) self.setPixel(x, y-2, colors.BLACK) @@ -85,6 +75,7 @@ class CharacterDisplay: self.setPixel(x, y-4, colors.BLACK) self.setPixel(x+1, y-3, colors.BLACK) self.setPixel(x+1, y-4, colors.BLACK) + self.unicorn.show() def displayZero(self, x, y, color): self.fullLine(x, y, color) diff --git a/time_display.py b/time_display.py index ad83690..c0c4d53 100644 --- a/time_display.py +++ b/time_display.py @@ -30,7 +30,7 @@ class TimeDisplay: if hour[0] != self.currentHour[0]: self.currentHour[0] = hour[0] - if hour[0] == 0: + if hour[0] == '0': self.hideDigit(self.hourStartColumn) else: self.showDigit(self.hourStartColumn, hour[0]) @@ -71,4 +71,4 @@ class TimeDisplay: def getTimeDigits(self, format): digits = datetime.now().strftime(format).strip().rjust(2, '0') - return [int(x) for x in digits] + return list(digits) diff --git a/weather_display.py b/weather_display.py index 3123b09..5e93b58 100644 --- a/weather_display.py +++ b/weather_display.py @@ -9,39 +9,51 @@ class WeatherDisplay: 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') + host = config['weather'].get('host') + user = config['weather'].get('user') + password = config['weather'].get('pass') + lat = config['weather'].get('lat') + lon = config['weather'].get('lon') - print(self.host) + self.uri = f'https://{host}/api/weather?lat={lat}&lon={lon}&units=metric' + self.auth = (user, password) def showWeather(self): - self.characterDisplay.clearRow(self.topRow) - self.showTemperature( - self.getTemperatureCharacters(self.getTemperature())) + try: + self.showTemperature( + self.getTemperatureCharacters(self.getTemperature())) + except requests.exceptions.ConnectionError: + print("connection error", flush=True) + self.characterDisplay.clearRow(self.topRow) + except requests.exceptions.Timeout: + print("timeout", flush=True) + self.characterDisplay.clearRow(self.topRow) def showTemperature(self, temperature): - start = 13 if ( len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1 else 9 + if temperature != self.currentTemperature: + self.characterDisplay.clearRow(self.topRow) - for c in temperature: - if c == '-': - self.characterDisplay.displayNegative( - start-3, self.topRow, self.color) - else: - self.characterDisplay.displayDigit( - start, self.topRow, c, self.color) - start = start + 4 + start = 13 if ( + len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1 else 9 + + for c in temperature: + if c == '-': + self.characterDisplay.displayNegative( + start-3, self.topRow, self.color) + else: + self.characterDisplay.displayDigit( + start, self.topRow, c, self.color) + start = start + 4 + + self.currentTemperature = temperature 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"] + return list(filter(lambda t: t["timestep"] == 'current', requests.get(self.uri, auth=self.auth, timeout=2).json()["tomorrow"]["data"]['timelines']))[0]["intervals"][0]["values"]["temperature"] def getTemperatureCharacters(self, temperature): return list(str(round(temperature)))