feat: web polling version, with day flag
This commit is contained in:
parent
b951bfe9fd
commit
110944600d
135
akl.go
135
akl.go
|
@ -2,63 +2,56 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/mmcdole/gofeed"
|
||||
)
|
||||
|
||||
var feeds = []string{
|
||||
"http://anarchief.org/w/index.php?title=Special:NewPages&feed=rss",
|
||||
"http://www.christianarchy.nl/feeds/posts/default?alt=rss",
|
||||
"https://1872dh.noblogs.org/feed",
|
||||
"https://aagu.nl/rss",
|
||||
"https://abcnijmegen.wordpress.com/feed",
|
||||
"https://afadenhaag.wordpress.com/feed",
|
||||
"https://afanl.wordpress.com/rss",
|
||||
"https://afarotterdam.noblogs.org/feed",
|
||||
"https://affverzet.wordpress.com/feed",
|
||||
"https://anticrust0.noblogs.org/feed",
|
||||
"https://antifabrabant.noblogs.org/rss",
|
||||
"https://antithese.blackblogs.org/feed",
|
||||
"https://autonomenbrabant.blackblogs.org/feed",
|
||||
"https://bondprecairewoonvormen.nl/feed",
|
||||
"https://buitendeorde.org/categorie/nieuws/rss",
|
||||
"https://crimethinc.com/feed/nl",
|
||||
"https://gentabc.noblogs.org/feed",
|
||||
"https://hetactiefonds.nl/feed",
|
||||
"https://indy.puscii.nl/rss.xml",
|
||||
"https://jokekaviaar.nl/rss",
|
||||
"https://kafka.nl/feed",
|
||||
"https://kraai.noblogs.org/rss",
|
||||
"https://libertaireorde.wordpress.com/feed",
|
||||
"https://nobordercamps.eu/rss",
|
||||
"https://onderstroom.red/alle-afleveringen/rss",
|
||||
"https://opstand.noblogs.org/feed",
|
||||
"https://peterstormt.nl/author/ravotr/rss",
|
||||
"https://pinksterlanddagen.org/rss",
|
||||
"https://rotterdamserats.blackblogs.org/rss",
|
||||
"https://rumoer.noblogs.org/rss",
|
||||
"https://stopwapenhandel.org/rss",
|
||||
"https://tabularasa.blackblogs.org/feed",
|
||||
"https://tanarchos.nl/feed",
|
||||
"https://thebarricade.noblogs.org/feed",
|
||||
"https://vloerwerk.org/feed",
|
||||
"https://vrijesocialist.wordpress.com/rss",
|
||||
"https://vrijparkerenleiden.blackblogs.org/events/rss",
|
||||
"https://vrijparkerenleiden.blackblogs.org/rss",
|
||||
"https://www.2dh5.nl/rss",
|
||||
"https://www.agamsterdam.org/rss",
|
||||
"https://www.burojansen.nl/rss",
|
||||
"https://www.doorbraak.eu/feed",
|
||||
"https://www.globalinfo.nl/feed",
|
||||
"https://www.grutjes.nl/feed",
|
||||
"https://www.hierlinksaf.nl/Podcast/ABC/feed.xml",
|
||||
"https://www.hierlinksaf.nl/Podcast/Audioboek/feed.xml",
|
||||
"https://www.konfrontatie.nl/recente-bijdragen?format=feed&type=rss",
|
||||
"https://www.vrijebond.org/feed",
|
||||
"https://zwartetulp.noblogs.org/rss",
|
||||
// layoutUS is a human friendly date format.
|
||||
const layoutUS = "January 2, 2006"
|
||||
|
||||
// feed is an RSS feed.
|
||||
type feed struct {
|
||||
Slug string `json:"slug"` // Slug for the RSS feed
|
||||
Title string `json:"title"` // Title of the RSS feed
|
||||
Url string `json:"url"` // URL of the RSS feed
|
||||
}
|
||||
|
||||
// item is a single RSS feed item.
|
||||
type item struct {
|
||||
link string
|
||||
published *time.Time
|
||||
title string
|
||||
}
|
||||
|
||||
// getFeeds retrieves all feeds from the FvA website API.
|
||||
func getFeeds() ([]feed, error) {
|
||||
var feeds []feed
|
||||
|
||||
url := "https://test.fva.wtf/api/anarchokrant-list"
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return feeds, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return feeds, err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &feeds); err != nil {
|
||||
return feeds, err
|
||||
}
|
||||
|
||||
return feeds, nil
|
||||
}
|
||||
|
||||
// parseRSSFeed parses a RSS feed.
|
||||
|
@ -75,34 +68,26 @@ func parseRSSFeed(url string) (gofeed.Feed, error) {
|
|||
return *feed, nil
|
||||
}
|
||||
|
||||
// item represents a single RSS feed item.
|
||||
type item struct {
|
||||
link string
|
||||
published *time.Time
|
||||
title string
|
||||
}
|
||||
|
||||
func linksFromFeed(feed string, ch chan<- []item) {
|
||||
func linksFromFeed(day int, feed string, ch chan<- []item) {
|
||||
var items []item
|
||||
|
||||
parsed, err := parseRSSFeed(feed)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Printf("failed to parse feed: %s\n\n", feed)
|
||||
ch <- items
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
lastMonth := now.AddDate(0, -1, 0)
|
||||
lastMonth := time.Date(now.Year(), now.Month()-1, day, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
for _, i := range parsed.Items {
|
||||
if i.PublishedParsed.Before(lastMonth) {
|
||||
continue
|
||||
if i.PublishedParsed.After(lastMonth) {
|
||||
items = append(items, item{
|
||||
link: i.Link,
|
||||
published: i.PublishedParsed,
|
||||
title: i.Title,
|
||||
})
|
||||
}
|
||||
|
||||
items = append(items, item{
|
||||
link: i.Link,
|
||||
published: i.PublishedParsed,
|
||||
title: i.Title,
|
||||
})
|
||||
}
|
||||
|
||||
ch <- items
|
||||
|
@ -110,14 +95,22 @@ func linksFromFeed(feed string, ch chan<- []item) {
|
|||
|
||||
// show outputs an item.
|
||||
func (i item) show() {
|
||||
fmt.Printf("%s\n%s\n\n", i.title, i.link)
|
||||
fmt.Printf("%s\n%s\n%s\n\n", i.published.Format(layoutUS), i.title, i.link)
|
||||
}
|
||||
|
||||
func main() {
|
||||
ch := make(chan []item, len(feeds))
|
||||
var dayFlag int
|
||||
flag.IntVar(&dayFlag, "d", 28, "day of last month")
|
||||
flag.Parse()
|
||||
|
||||
feeds, err := getFeeds()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ch := make(chan []item, len(feeds))
|
||||
for _, feed := range feeds {
|
||||
go linksFromFeed(feed, ch)
|
||||
go linksFromFeed(dayFlag, feed.Url, ch)
|
||||
}
|
||||
|
||||
for range feeds {
|
||||
|
|
Loading…
Reference in New Issue