63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/jinzhu/now"
|
|
"p83.nl/go/ekster/pkg/microsub"
|
|
"willnorris.com/go/microformats"
|
|
|
|
"p83.nl/go/ekster/pkg/jf2"
|
|
)
|
|
|
|
func main() {
|
|
u, err := url.Parse(os.Args[1])
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
resp, err := http.Get(u.String())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != 200 {
|
|
log.Fatalf("Status is not 200, but %d", resp.StatusCode)
|
|
}
|
|
|
|
md := microformats.Parse(resp.Body, u)
|
|
items := jf2.SimplifyMicroformatDataItems(md)
|
|
|
|
items = filterEntriesAfter(items, now.With(time.Now()).Monday())
|
|
|
|
t, err := template.ParseFiles("templates/weekly.html")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
err = t.Execute(os.Stdout, items)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func filterEntriesAfter(items []microsub.Item, from time.Time) []microsub.Item {
|
|
var result []microsub.Item
|
|
for _, item := range items {
|
|
published, err := time.Parse(time.RFC3339, item.Published)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if published.After(from) {
|
|
result = append(result, item)
|
|
}
|
|
}
|
|
return result
|
|
}
|