Fix weather formatting
This commit is contained in:
parent
5168f5d3de
commit
132005d938
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
@ -10,7 +11,7 @@ class WeatherDisplay:
|
||||||
self.currentTemperature = [9, 9]
|
self.currentTemperature = [9, 9]
|
||||||
self.currentColor = colors.BLACK
|
self.currentColor = colors.BLACK
|
||||||
self.color = colors.BLUE
|
self.color = colors.BLUE
|
||||||
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(configFile)
|
config.read(configFile)
|
||||||
|
|
||||||
|
@ -23,22 +24,24 @@ 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:
|
|
||||||
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
|
|
||||||
|
|
||||||
|
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):
|
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):
|
def getTemperatureCharacters(self, temperature):
|
||||||
return list(str(round(temperature)))
|
return list(str(round(temperature)))
|
||||||
|
|
Loading…
Reference in New Issue