70 lines
1.3 KiB
Plaintext
70 lines
1.3 KiB
Plaintext
#!/usr/local/bin/gentee
|
|
|
|
const : URL = "https://wttr.in/"
|
|
const : URLV2 = "https://v2.wttr.in/"
|
|
const : URLV3 = "https://v3.wttr.in/"
|
|
const : MOONURL = "https://wttr.in/moon@"
|
|
|
|
func dirs() arr.str {
|
|
arr.str res = {
|
|
GetEnv("HOME")+"/.config/wttr/default-city.txt",
|
|
GetEnv("HOME")+"/.wttr",
|
|
}
|
|
return res
|
|
}
|
|
|
|
func help() str {
|
|
return Format(`
|
|
Usage: wttr <region>
|
|
-v2
|
|
Use v2 (%s)
|
|
-v3
|
|
Use v3 (%s)
|
|
-m
|
|
display moon (%s)
|
|
-c
|
|
Use metric units
|
|
-f
|
|
Use imperial units
|
|
-t -today
|
|
Display today's weather
|
|
`,
|
|
URLV2,
|
|
URLV3,
|
|
MOONURL,
|
|
)
|
|
}
|
|
|
|
func request(str url) str {
|
|
map empty
|
|
map headers = {"User-Agent":"curl/7.87"}
|
|
return HTTPRequest(url, "GET", empty, headers)
|
|
}
|
|
|
|
run {
|
|
if IsArg("h") || IsArg("help") {
|
|
Println(help())
|
|
return
|
|
}
|
|
str loc = Arg("")
|
|
str url = URL
|
|
for fl in dirs() {
|
|
if ExistFile(fl): loc = TrimSpace(ReadFile(fl)); break;
|
|
}
|
|
if IsArg("v2"): url = URLV2
|
|
if IsArg("v3"): url = URLV3
|
|
if IsArg("m"): url = MOONURL
|
|
switch Arg("")
|
|
case "":
|
|
default: loc = Arg("")
|
|
switch loc
|
|
case "": url = url + "?"
|
|
default: url = url + loc +"?"
|
|
if IsArg("c"): url = url + "&m"
|
|
if IsArg("f"): url = url + "&u"
|
|
if (IsArg("t")||IsArg("today")): url = url + "&1n"
|
|
//Print(request(url))
|
|
Run(`head`,"-n","-1", stdin: buf(request(url)))
|
|
}
|
|
|