fixed weather crashing when 404
This commit is contained in:
parent
27c0073d2a
commit
7d48fa6889
21
commands.py
21
commands.py
|
@ -236,11 +236,18 @@ class Command:
|
|||
argsplit = cmd.split("?")[1].split()
|
||||
if "f" in argsplit or "u" in argsplit:
|
||||
mf = "u" # farenheit
|
||||
a = __import__("http.client").client.HTTPSConnection("wttr.in")
|
||||
x=__import__("urllib.parse").parse
|
||||
y=x.urlsplit(f"https://wttr.in/{loc}?A&T&0&n&F&{mf}")
|
||||
y=x.urlunsplit((y.scheme, y.netloc, x.quote(y.path), y.query, y.fragment))
|
||||
a=__import__("urllib.request").request.urlopen(y)
|
||||
b=a.read().decode("utf-8")
|
||||
mesg(b.split("\n")[0].strip()+" "+" ".join(b.split("\n")[3].strip().split(" ")[-2:]))
|
||||
try:
|
||||
a = __import__("http.client").client.HTTPSConnection("wttr.in")
|
||||
x = __import__("urllib.parse").parse
|
||||
y = x.urlsplit(f"https://wttr.in/{loc}?A&T&0&n&F&{mf}")
|
||||
y = x.urlunsplit((y.scheme, y.netloc, x.quote(y.path), y.query, y.fragment))
|
||||
a = __import__("urllib.request").request.urlopen(y)
|
||||
b = a.read().decode("utf-8")
|
||||
mesg(
|
||||
b.split("\n")[0].strip()
|
||||
+ " "
|
||||
+ " ".join(b.split("\n")[3].strip().split(" ")[-2:])
|
||||
)
|
||||
except Exception as e:
|
||||
mesg(f"{type(e).__name__} was raised: {e}")
|
||||
# mesg(cmd.split(" ", 1)[1])
|
||||
|
|
Loading…
Reference in New Issue