Fix weather formatting
This commit is contained in:
parent
5168f5d3de
commit
132005d938
|
@ -59,6 +59,13 @@ class CharacterDisplay:
|
|||
|
||||
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):
|
||||
self.setPixel(x, y, colors.BLACK)
|
||||
self.setPixel(x, y-1, color)
|
||||
|
|
|
@ -37,7 +37,6 @@ def main():
|
|||
|
||||
if (x == 0):
|
||||
weatherDisplay.showWeather()
|
||||
print("weather updated")
|
||||
|
||||
x = x + 1
|
||||
x = x % 120
|
||||
|
|
|
@ -3,6 +3,7 @@ import requests
|
|||
|
||||
from configparser import ConfigParser
|
||||
|
||||
|
||||
class WeatherDisplay:
|
||||
def __init__(self, characterDisplay, topRow, configFile):
|
||||
self.characterDisplay = characterDisplay
|
||||
|
@ -23,22 +24,24 @@ class WeatherDisplay:
|
|||
print(self.host)
|
||||
|
||||
def showWeather(self):
|
||||
self.showTemperature(self.getTemperatureCharacters(self.getTemperature()))
|
||||
self.characterDisplay.clearRow(self.topRow)
|
||||
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
|
||||
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
|
||||
|
||||
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"]
|
||||
|
||||
def getTemperatureCharacters(self, temperature):
|
||||
return list(str(round(temperature)))
|
||||
return list(str(round(temperature)))
|
||||
|
|
Loading…
Reference in New Issue