master
parent
5722f37916
commit
5d91288992
51
main.go
51
main.go
|
|
@ -9,10 +9,15 @@ listing file.
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"local/args"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -24,11 +29,45 @@ func main() {
|
|||
}
|
||||
|
||||
d := fs.Get("d").GetString()
|
||||
p := strings.TrimPrefix(fs.Get("p").GetString(), ":")
|
||||
p := fs.Get("p").GetString()
|
||||
go serve(d, p)
|
||||
go poll(path.Join(d, "csv"), time.Minute)
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(d)))
|
||||
|
||||
log.Printf("Serving %s on HTTP port: %s\n", d, p)
|
||||
|
||||
log.Fatal(http.ListenAndServe(":"+p, nil))
|
||||
<-context.Background().Done()
|
||||
}
|
||||
|
||||
func serve(directory, port string) {
|
||||
port = strings.TrimPrefix(port, ":")
|
||||
http.Handle("/", http.FileServer(http.Dir(directory)))
|
||||
log.Printf("Serving %s on HTTP port: %s\n", directory, port)
|
||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
||||
}
|
||||
|
||||
func poll(path string, interval time.Duration) {
|
||||
for {
|
||||
select {
|
||||
case <-context.Background().Done():
|
||||
case <-time.After(interval):
|
||||
if err := refresh(path); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func refresh(path string) error {
|
||||
url := "https://docs.google.com/spreadsheets/d/14F7zRrwGT6JkCeZqZLPM2r2GScrm9FLFxlPtDINbNWg/gviz/tq?tqx=out:csv"
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(path, b, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
"Link to Ride","Date","Day","Time","Route","Start","Notes"
|
||||
"https://ridewithgps.com/routes/29835879","May 11","Sat","9:00 AM","Hobble Creek R & L Forks 86-Mi","OLD Bike Peddler 24 E Main American Fork","Great way to start the cycling year with good friends! Weather Permitting"
|
||||
"","May 11","Sat","9:45 AM","64-Mile Ride Hobble Creek R & L Forks","Gas Station 1600 E 800 N Orem","Same route as last week."
|
||||
"","May 13","Mon","5:45 AM","Spin Class","VASA Fitness American Fork","High Intensity group workout on new spin bikes"
|
||||
|
|
@ -106,10 +106,11 @@
|
|||
var google_doc_pre = "https://docs.google.com/spreadsheets/d/"
|
||||
var google_doc_id = "14F7zRrwGT6JkCeZqZLPM2r2GScrm9FLFxlPtDINbNWg"
|
||||
var google_doc_post = "/gviz/tq?tqx=out:csv"
|
||||
//`${cors_anywhere}/${google_doc_pre}/${google_doc_id}/${google_doc_post}`,
|
||||
|
||||
http(
|
||||
"get",
|
||||
`${cors_anywhere}/${google_doc_pre}/${google_doc_id}/${google_doc_post}`,
|
||||
window.location+"/csv",
|
||||
populate_schedule,
|
||||
JSON.stringify({"cc": "cc"}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue