-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwttr.py
45 lines (36 loc) · 1.24 KB
/
wttr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
import requests #type: ignore
def getArg(idx: int,detail):
if len(sys.argv) > idx:
return sys.argv[idx]
else:
print(f"wttr {detail["command"]} ****")
print(f"expected argument where{" "*abs(int(len(detail["command"])-16))}^^ ")
print(f"reason:\n{detail["reason"]}")
sys.exit(1)
def Usage():
print("Usage: wttr [command]? [args*]?")
sys.exit(1)
def Failed(text: str):
print(text)
sys.exit(1)
BASE = "https://wttr.in"
if len(sys.argv) < 1:
Usage()
command = getArg(1,{"command":"[command]","reason":"require a command to run!"})
match command:
case "place" | "where" | "domain" | "location" | "in":
response = requests.get(BASE+"/"+getArg(2,{"command":"'place' | 'where' | 'domain' | 'location' | 'in'","reason":"require a location or a domain"}))
if response.ok:
print(response.text)
else:
Failed(response.reason)
case "help" | "-help":
print("Unofficial wttr.in cli tool")
Usage()
case _:
response = requests.get(BASE+"/"+getArg(2,{"command":"","reason":"require a location or a domain"}))
if response.ok:
print(response.text)
else:
Failed(response.reason)