Now with weather
This commit is contained in:
parent
4ee2f78e48
commit
e92d649451
@ -4,7 +4,7 @@ import datetime
|
||||
|
||||
def show_weather(location):
|
||||
url = "https://api.openweathermap.org/data/2.5/onecall?"
|
||||
data = {"lat" : location[0], "lon" : location[1], "exclude" : "minutely,hourly", "appid" : api.keys.weather_api, "units" : "metric"}
|
||||
data = {"lat" : location[0], "lon" : location[1], "exclude" : "minutely,hourly", "appid" : bot.api.keys.weather_api, "units" : "metric"}
|
||||
today = datetime.datetime.today().weekday()
|
||||
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
||||
|
||||
|
@ -155,7 +155,6 @@ class ChatBot():
|
||||
city = locations[params[0].lower().replace("ü","u")]
|
||||
else:
|
||||
return "Couldn't find city, it might be added later though."
|
||||
return
|
||||
|
||||
message = weather.show_weather(city)
|
||||
|
||||
|
33
clock.py
33
clock.py
@ -10,20 +10,49 @@ class ModuleWrapper():
|
||||
def __init__(self, module_name):
|
||||
""""""
|
||||
self.clock = clock.main.ClockFace()
|
||||
self.bot = bot.main.ChatBot("Clockbot","1.1")
|
||||
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",
|
||||
}
|
||||
|
||||
|
||||
def mainloop(self):
|
||||
"""Runs the showing of the clock-face periodically (better way?)"""
|
||||
prev_time = 0
|
||||
prev_weather_time = datetime.datetime.fromtimestamp(0)
|
||||
while True:
|
||||
if prev_time == datetime.datetime.now().strftime("%H:%M"):
|
||||
time.sleep(10)
|
||||
else:
|
||||
d = datetime.datetime.now() - prev_weather_time
|
||||
if d.total_seconds() >= 3*3600:
|
||||
prev_weather_time = datetime.datetime.now()
|
||||
weather = self.bot.bot_show_weather(["zurich"])
|
||||
offset = weather.find("</b>") + 6
|
||||
weather = weather[offset:]
|
||||
weather = weather[:weather.find(":")]
|
||||
self.weather = weather
|
||||
|
||||
prev_time = datetime.datetime.now().strftime("%H:%M")
|
||||
self.clock.set_face("sun")
|
||||
self.clock.set_face(self.categories[self.weather])
|
||||
|
||||
|
||||
test = ModuleWrapper("clock")
|
||||
ModuleWrapper("clock")
|
||||
|
@ -75,7 +75,7 @@ def weather_converter(name):
|
||||
icons = Image.open(icon_spritesheet)
|
||||
icons_full = np.array(icons)
|
||||
print(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", "thunder and cloud", "thunder and cloud and moon", "snow and cloud", "snow and cloud and moon", "fog","fog night"]
|
||||
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 ...
|
||||
try:
|
||||
iy, ix = int(icon_loc.index(name)/2), icon_loc.index(name)%2
|
||||
|
Loading…
x
Reference in New Issue
Block a user