2019-12-22 09:52:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
2019-12-22 10:10:11 +00:00
|
|
|
"time"
|
2019-12-22 09:52:43 +00:00
|
|
|
|
2019-12-22 10:10:11 +00:00
|
|
|
"github.com/jinzhu/now"
|
|
|
|
"p83.nl/go/ekster/pkg/microsub"
|
2019-12-22 09:52:43 +00:00
|
|
|
"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)
|
|
|
|
|
2019-12-22 10:10:11 +00:00
|
|
|
items = filterEntriesAfter(items, now.With(time.Now()).Monday())
|
|
|
|
|
2019-12-22 09:52:43 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2019-12-22 10:10:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|