Added a temperature display for weather. Currently can't show negative temps
This commit is contained in:
parent
b4ce9eadf9
commit
f5499c144b
@ -17,11 +17,15 @@ def show_weather(location):
|
||||
categories = {"Clouds": ":cloud:", "Rain": ":cloud_with_rain:", "Thunderstorm": "thunder_cloud_rain", "Drizzle": ":droplet:", "Snow": ":cloud_snow:", "Clear": ":sun:", "Mist": "Mist", "Smoke": "Smoke", "Haze": "Haze", "Dust": "Dust", "Fog": "Fog", "Sand": "Sand", "Dust": "Dust", "Ash": "Ash", "Squall": "Squall", "Tornado": "Tornado",}
|
||||
|
||||
now = weather["current"]
|
||||
message = "<b>Today:</b> " + categories[now["weather"][0]["main"]] + "\n"
|
||||
message = "<b>Now:</b> " + categories[now["weather"][0]["main"]] + "\n"
|
||||
message += ":thermometer: " + str(int(now["temp"])) + "°\n\n"
|
||||
|
||||
for i, day in enumerate(weather["daily"]):
|
||||
weather_days = weather["daily"]
|
||||
|
||||
for i, day in enumerate(weather_days):
|
||||
if i == 0:
|
||||
message += "<b>" + "Today" + ":</b> " + categories[day["weather"][0]["main"]] + "\n"
|
||||
else:
|
||||
message += "<b>" + days[(today + i + 1) % 7] + ":</b> " + categories[day["weather"][0]["main"]] + "\n"
|
||||
message += ":thermometer: :fast_down_button: " + str(int(day["temp"]["min"])) + "° , :thermometer: :fast_up_button: " + str(int(day["temp"]["max"])) + "°\n\n"
|
||||
|
||||
|
@ -33,10 +33,10 @@ digits = {
|
||||
##place of numbers, invariable
|
||||
digit_position = [[2,4], [2,10], [9,4], [9,10]]
|
||||
|
||||
def time_converter():
|
||||
def time_converter(time=datetime.datetime.now().strftime("%H%M")):
|
||||
"""Converts 4-digit time to a pixel-matrix
|
||||
returns: np.array((16, 16))"""
|
||||
time = datetime.datetime.now().strftime("%H%M")
|
||||
#time = datetime.datetime.now().strftime("%H%M")
|
||||
pixels = np.zeros((16,16),dtype=np.uint8)
|
||||
time = "0" * (4 - len(str(time))) + str(time)
|
||||
time_split = [int(i) for i in time]
|
||||
@ -64,6 +64,27 @@ def date_converter():
|
||||
return pixels
|
||||
|
||||
|
||||
|
||||
|
||||
weather_categories = {
|
||||
"cloud": "cloud",
|
||||
"cloud_with_rain": "rain and cloud",
|
||||
"thunder_cloud_rain": "thunder and cloud",
|
||||
"droplet": "rain and cloud",
|
||||
"cloud_snow": "snow and cloud",
|
||||
"sun": "sun",
|
||||
"Mist": "fog and clouds",
|
||||
"Smoke": "Smoke",
|
||||
"Haze": "Haze",
|
||||
"Dust": "Dust",
|
||||
"Fog": "fog",
|
||||
"Sand": "Sand",
|
||||
"Dust": "Dust",
|
||||
"Ash": "Ash",
|
||||
"Squal": "Squal",
|
||||
"Tornado": "Tornado",
|
||||
}
|
||||
|
||||
def weather_converter(name):
|
||||
result = np.zeros((16,16))
|
||||
cwd = __file__.replace("\\","/") # for windows
|
||||
@ -77,6 +98,7 @@ def weather_converter(name):
|
||||
|
||||
icon_loc = ["sun","moon","sun and clouds", "moon and clouds", "cloud","fog and clouds","2 clouds", "3 clouds", "rain and cloud", "rain and clouds", "rain and cloud and sun", "rain and cloud and moon", "thunder and cloud", "thunder and cloud and moon", "snow and cloud", "snow and cloud and moon", "fog","fog night"]
|
||||
#ordered 1 2 \n 3 4 \ 5 5 ...
|
||||
name = weather_categories[name]
|
||||
try:
|
||||
iy, ix = int(icon_loc.index(name)/2), icon_loc.index(name)%2
|
||||
# x and y coords
|
||||
|
@ -43,11 +43,11 @@ class OutputHandler():
|
||||
c1 = self.primary
|
||||
c2 = self.secondary
|
||||
c3 = self.red
|
||||
if len(colors) == 1:
|
||||
if len(colors) > 0:
|
||||
c1 = colors[0]
|
||||
if len(colors) == 2:
|
||||
if len(colors) > 1:
|
||||
c2 = colors[1]
|
||||
if len(colors) == 3:
|
||||
if len(colors) > 2:
|
||||
c3 = colors[2]
|
||||
if len(colors) > 3:
|
||||
print("Too many colors")
|
||||
@ -68,7 +68,6 @@ class OutputHandler():
|
||||
return r3
|
||||
|
||||
|
||||
|
||||
def set_matrix_rgb(self, matrix, quadrant=1):
|
||||
result = np.zeros((self.height, self.width,3))
|
||||
if quadrant == 1:
|
||||
@ -83,14 +82,21 @@ class OutputHandler():
|
||||
self.output.set_matrix(result)
|
||||
|
||||
|
||||
def clock_face(self,weather):
|
||||
def clock_face(self, weather):
|
||||
"""weather as a dict"""
|
||||
hour = converter.time_converter()
|
||||
day = converter.date_converter()
|
||||
face1 = hour + day
|
||||
face1_3d = self.matrix_add_depth(face1)
|
||||
|
||||
print(weather)
|
||||
if weather["show"] == "weather":
|
||||
face2_3d = converter.weather_converter(weather["weather"])
|
||||
else:
|
||||
face2 = converter.time_converter(int(weather["low"]+weather["high"]))
|
||||
face2 = np.concatenate((face2[:8,...],2*face2[8:,...]))
|
||||
face2_3d = self.matrix_add_depth(face2,[[10,10,200],[200,10,10]])
|
||||
|
||||
face2_3d = converter.weather_converter(weather)
|
||||
face = np.zeros((max(face1_3d.shape[0],face2_3d.shape[0]),face1_3d.shape[1]+face2_3d.shape[1],3))
|
||||
|
||||
face[:face1_3d.shape[0],:face1_3d.shape[1],...] = face1_3d
|
||||
|
@ -131,6 +131,7 @@ class ClockFace(object):
|
||||
|
||||
self.run(output,(image, duration))
|
||||
|
||||
|
||||
def show_message(self, *args):
|
||||
"""Runs a text message over the screen. Obviously needs the text"""
|
||||
# keep in mind, in this case args is a tuple of all words
|
||||
|
@ -12,25 +12,7 @@ class ModuleWrapper():
|
||||
self.bot = bot_module
|
||||
self.time_thread = Thread(target=self.mainloop)
|
||||
self.time_thread.start()
|
||||
self.weather = ""
|
||||
self.categories = categories = {
|
||||
"cloud": "cloud",
|
||||
"cloud_with_rain": "rain and cloud",
|
||||
"thunder_cloud_rain": "thunder and cloud",
|
||||
"droplet": "rain and cloud",
|
||||
"cloud_snow": "snow and cloud",
|
||||
"sun": "sun",
|
||||
"Mist": "fog and clouds",
|
||||
"Smoke": "Smoke",
|
||||
"Haze": "Haze",
|
||||
"Dust": "Dust",
|
||||
"Fog": "fog",
|
||||
"Sand": "Sand",
|
||||
"Dust": "Dust",
|
||||
"Ash": "Ash",
|
||||
"Squal": "Squal",
|
||||
"Tornado": "Tornado",
|
||||
}
|
||||
self.weather = {"weather":"", "high":"", "low":"", "show":"weather"}
|
||||
|
||||
|
||||
def mainloop(self):
|
||||
@ -40,17 +22,34 @@ class ModuleWrapper():
|
||||
prev_weather_time = datetime.datetime.fromtimestamp(0)
|
||||
while True:
|
||||
if prev_time == datetime.datetime.now().strftime("%H:%M"):
|
||||
time.sleep(10)
|
||||
time.sleep(15)
|
||||
else:
|
||||
d = datetime.datetime.now() - prev_weather_time
|
||||
if d.total_seconds() >= 3*3600:
|
||||
mins_elapsed = int(d.total_seconds()/60)
|
||||
|
||||
if mins_elapsed >= 3*60:
|
||||
# fetch new weather every 3 hours (hard coded)
|
||||
prev_weather_time = datetime.datetime.now()
|
||||
weather = self.bot.bot_show_weather("zurich")
|
||||
l1 = weather[:weather.find("\n")]
|
||||
l1 = l1.replace("<b>Today:</b> ","")
|
||||
l1 = l1.replace (":","")
|
||||
self.weather = l1
|
||||
|
||||
l1 = weather[weather.find("</b>")+5:weather.find("\n")].replace (":","")
|
||||
# current weather situation (icon): we pick the first line, remove the start string, remove :: indicating an emoji
|
||||
|
||||
temps_today = weather.splitlines()[4]
|
||||
low = temps_today[temps_today.find("button")+8:temps_today.find("°")]
|
||||
temps_today = temps_today[temps_today.find("°") + 1:]
|
||||
high = temps_today[temps_today.find("button")+8:temps_today.find("°")]
|
||||
self.weather["weather"] = l1
|
||||
self.weather["high"] = high
|
||||
self.weather["low"] = low
|
||||
|
||||
if mins_elapsed % 5 == 0:
|
||||
if self.weather["show"] == "weather":
|
||||
next = "temps"
|
||||
else:
|
||||
next = "weather"
|
||||
self.weather["show"] = next
|
||||
|
||||
prev_time = datetime.datetime.now().strftime("%H:%M")
|
||||
|
||||
self.clock.set_face(self.categories[self.weather])
|
||||
self.clock.set_face(self.weather)
|
||||
|
@ -10,7 +10,6 @@ from threading import Thread
|
||||
|
||||
|
||||
|
||||
|
||||
class Launcher():
|
||||
"""Launches all other submodules"""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user