commit 0978f978d421da1b9496d1e40c77c7a5d8e8c9fe
parent 58630136633fdb05451bda3a13bd6fa8f869cb02
Author: Demonstrandum <moi@knutsen.co>
Date: Mon, 8 Feb 2021 15:27:18 +0000
Added weather reporting with wttr.in
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/main.go b/main.go
@@ -5,6 +5,7 @@ import ("os/exec"; "time"; "bufio")
import "strings"
import "path/filepath"
import "text/template"
+import "net/http"
import "github.com/pitr/gig"
@@ -122,6 +123,24 @@ func main() {
})
s.Handle("/", defaultView("index"))
+ s.Handle("weather", func(c gig.Context) error {
+ query, err := c.QueryString()
+ if err != nil { return err }
+
+ if query == "" {
+ return c.NoContent(gig.StatusInput, "Enter your location.")
+ }
+
+ loc := strings.Join(strings.Split(query, " "), "+")
+ res, err := http.Get("https://wttr.in/" + loc + "?AF0")
+ if err != nil || res.StatusCode != http.StatusOK {
+ return gig.ErrProxyError
+ }
+ defer res.Body.Close()
+
+ return c.Stream("text/html", res.Body)
+ })
+
user := s.Group("/~:name")
{
fileView := func(file string) (func(gig.Context) error) {
diff --git a/views/index.gmi b/views/index.gmi
@@ -13,6 +13,7 @@ Gemini homepage, hosted on a VPS somewhere in London.
### Index
=> /music Music?
+=> /weather Get the weather.
## Users
Want to host personal pages here? E-mail me your desired username and public