Fixing weather api issues
This commit is contained in:
parent
7debff33ab
commit
af839dd842
@ -10,10 +10,7 @@ def show_weather(location):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
weather = requests.get(url,params=data).json()
|
weather = requests.get(url,params=data).json()
|
||||||
except:
|
print("WEATHER API CALLED")
|
||||||
return "Query failed, it's my fault, I'm sorry :sad:"
|
|
||||||
|
|
||||||
|
|
||||||
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",}
|
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"]
|
now = weather["current"]
|
||||||
@ -28,5 +25,6 @@ def show_weather(location):
|
|||||||
else:
|
else:
|
||||||
message += "<b>" + days[(today + i + 1) % 7] + ":</b> " + categories[day["weather"][0]["main"]] + "\n"
|
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"
|
message += ":thermometer: :fast_down_button: " + str(int(day["temp"]["min"])) + "° , :thermometer: :fast_up_button: " + str(int(day["temp"]["max"])) + "°\n\n"
|
||||||
|
except:
|
||||||
|
return "Query failed, it's my fault, I'm sorry :sad:"
|
||||||
return message
|
return message
|
||||||
|
12
bot/main.py
12
bot/main.py
@ -237,11 +237,17 @@ class ChatBot():
|
|||||||
|
|
||||||
|
|
||||||
def bot_print_log(self, *args):
|
def bot_print_log(self, *args):
|
||||||
"""Shows an error-log, mostly of bad api-requests"""
|
"""Shows an error-log, mostly of bad api-requests. Usage
|
||||||
|
log clear - clears log
|
||||||
|
log system - shows python output"""
|
||||||
|
|
||||||
if "clear" in args:
|
if "clear" in args:
|
||||||
self.persistence.write("log",[])
|
self.persistence.write("log",[])
|
||||||
self.telegram.send_message("Log cleared")
|
return "Log cleared"
|
||||||
return
|
elif "system" in args:
|
||||||
|
send_text = self.persistence.read_ext_file("log.txt")
|
||||||
|
return send_text
|
||||||
|
|
||||||
send_text = ""
|
send_text = ""
|
||||||
for event in self.persistence.read("log"):
|
for event in self.persistence.read("log"):
|
||||||
send_text += event + "\n"
|
send_text += event + "\n"
|
||||||
|
@ -30,6 +30,7 @@ digits = {
|
|||||||
"0" : [[1,1,1],[1,0,1],[1,0,1],[1,0,1],[1,1,1]],
|
"0" : [[1,1,1],[1,0,1],[1,0,1],[1,0,1],[1,1,1]],
|
||||||
"-" : [[0,0,0],[0,0,0],[1,1,1],[0,0,0],[0,0,0]],
|
"-" : [[0,0,0],[0,0,0],[1,1,1],[0,0,0],[0,0,0]],
|
||||||
"-1" : [[0,0,1],[0,0,1],[1,1,1],[0,0,1],[0,0,1]],
|
"-1" : [[0,0,1],[0,0,1],[1,1,1],[0,0,1],[0,0,1]],
|
||||||
|
"error" : [[1,0,1],[1,0,1],[0,1,0],[1,0,1],[1,0,1]],
|
||||||
}
|
}
|
||||||
|
|
||||||
##place of numbers, invariant
|
##place of numbers, invariant
|
||||||
@ -52,6 +53,8 @@ def time_converter(top="", bottom=""):
|
|||||||
|
|
||||||
if ("-" in top and len(top) > 2) or ("-" in bottom and len(bottom) > 2):
|
if ("-" in top and len(top) > 2) or ("-" in bottom and len(bottom) > 2):
|
||||||
time_split = 4*["-"]
|
time_split = 4*["-"]
|
||||||
|
elif "error" in top and "error" in bottom:
|
||||||
|
time_split = 4*["error"]
|
||||||
else:
|
else:
|
||||||
time_split = [i for i in top] + [i for i in bottom]
|
time_split = [i for i in top] + [i for i in bottom]
|
||||||
|
|
||||||
@ -102,6 +105,7 @@ weather_categories = {
|
|||||||
"Ash": "Ash",
|
"Ash": "Ash",
|
||||||
"Squal": "Squal",
|
"Squal": "Squal",
|
||||||
"Tornado": "Tornado",
|
"Tornado": "Tornado",
|
||||||
|
"error" : "moon"
|
||||||
}
|
}
|
||||||
|
|
||||||
def weather_converter(name):
|
def weather_converter(name):
|
||||||
|
@ -28,7 +28,7 @@ class ClockWrapper(wrapper.Wrapper):
|
|||||||
# fetch new weather every 3 hours (hard coded)
|
# fetch new weather every 3 hours (hard coded)
|
||||||
prev_weather_time = datetime.datetime.now()
|
prev_weather_time = datetime.datetime.now()
|
||||||
weather = self.others[0].bot_show_weather("zurich")
|
weather = self.others[0].bot_show_weather("zurich")
|
||||||
|
if not (sad in weather):
|
||||||
l1 = weather[weather.find("</b>")+5:weather.find("\n")].replace (":","")
|
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
|
# current weather situation (icon): we pick the first line, remove the start string, remove :: indicating an emoji
|
||||||
|
|
||||||
@ -39,6 +39,10 @@ class ClockWrapper(wrapper.Wrapper):
|
|||||||
self.weather["weather"] = l1
|
self.weather["weather"] = l1
|
||||||
self.weather["high"] = high
|
self.weather["high"] = high
|
||||||
self.weather["low"] = low
|
self.weather["low"] = low
|
||||||
|
else:
|
||||||
|
self.weather["weather"] = "error"
|
||||||
|
self.weather["high"] = "error"
|
||||||
|
self.weather["low"] = "error"
|
||||||
|
|
||||||
if mins_elapsed % 5 == 0:
|
if mins_elapsed % 5 == 0:
|
||||||
if self.weather["show"] == "weather":
|
if self.weather["show"] == "weather":
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
sleep 30
|
sleep 30
|
||||||
cd /home/pi/AIO
|
cd /home/pi/AIO
|
||||||
sudo python3 launcher.py
|
sudo python3 launcher.py > persistence/log.txt
|
||||||
|
0
persistence/log.txt
Normal file
0
persistence/log.txt
Normal file
@ -71,3 +71,13 @@ class Variables():
|
|||||||
pre = self.read(name)
|
pre = self.read(name)
|
||||||
pre.append(value)
|
pre.append(value)
|
||||||
self.write(name, pre)
|
self.write(name, pre)
|
||||||
|
|
||||||
|
|
||||||
|
def read_ext_file(self, path):
|
||||||
|
"""returns content of given file"""
|
||||||
|
if not os.path.exists(path):
|
||||||
|
return "File does not exist"
|
||||||
|
file = os.open(path,"r")
|
||||||
|
content = os.read(file)
|
||||||
|
os.close(file)
|
||||||
|
return content
|
Loading…
x
Reference in New Issue
Block a user