Fix weather formatting

This commit is contained in:
Mike Cifelli 2022-12-24 12:10:46 -05:00
parent 5168f5d3de
commit 132005d938
3 changed files with 23 additions and 14 deletions

View File

@ -59,6 +59,13 @@ class CharacterDisplay:
self.unicorn.show() self.unicorn.show()
def clearRow(self, y):
for row in range(y, y-5, -1):
for col in range(self.minX, self.maxX + 1):
self.setPixel(col, row, colors.BLACK)
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, colors.BLACK)
self.setPixel(x, y-1, color) self.setPixel(x, y-1, color)

View File

@ -37,7 +37,6 @@ def main():
if (x == 0): if (x == 0):
weatherDisplay.showWeather() weatherDisplay.showWeather()
print("weather updated")
x = x + 1 x = x + 1
x = x % 120 x = x % 120

View File

@ -3,6 +3,7 @@ import requests
from configparser import ConfigParser from configparser import ConfigParser
class WeatherDisplay: class WeatherDisplay:
def __init__(self, characterDisplay, topRow, configFile): def __init__(self, characterDisplay, topRow, configFile):
self.characterDisplay = characterDisplay self.characterDisplay = characterDisplay
@ -23,20 +24,22 @@ class WeatherDisplay:
print(self.host) print(self.host)
def showWeather(self): def showWeather(self):
self.showTemperature(self.getTemperatureCharacters(self.getTemperature())) self.characterDisplay.clearRow(self.topRow)
self.showTemperature(
self.getTemperatureCharacters(self.getTemperature()))
def showTemperature(self, temperature): def showTemperature(self, temperature):
start = 6 start = 13 if ( len(temperature) == 2 and temperature[0] == '-') or len(temperature) == 1 else 9
for c in temperature: for c in temperature:
if c == '-': if c == '-':
self.characterDisplay.displayNegative(start, self.topRow, self.color) self.characterDisplay.displayNegative(
start = start + 3 start-3, self.topRow, self.color)
else: else:
self.characterDisplay.displayDigit(start, self.topRow, c, self.color) self.characterDisplay.displayDigit(
start, self.topRow, c, self.color)
start = start + 4 start = start + 4
def getTemperature(self): 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(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"]