akl/akl.go

166 lines
4.1 KiB
Go

package main
import (
"context"
"fmt"
"log"
"net/url"
"time"
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/mmcdole/gofeed"
)
const layoutUS = "January 2, 2006"
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",
}
func htmlToMarkdown(content string) (string, error) {
converter := md.NewConverter("", true, nil)
markdown, err := converter.ConvertString(content)
if err != nil {
return markdown, fmt.Errorf("htmlToMarkdown: unable to convert html to markdown: %w", err)
}
return markdown, nil
}
func parseRSSFeed(url string) (gofeed.Feed, error) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
feedParser := gofeed.NewParser()
feed, err := feedParser.ParseURLWithContext(url, ctx)
if err != nil {
return gofeed.Feed{}, fmt.Errorf("parseRSSFeed: unable to parse %s: %w", url, err)
}
return *feed, nil
}
type item struct {
authors []string
content string
description string
link string
host string
published *time.Time
title string
}
func (i item) Print() {
fmt.Println(fmt.Sprintf("%s\n%s", i.title, i.link))
}
type items []item
func (i items) LastMonth() items {
var filtered []item
now := time.Now()
lastMonth := now.AddDate(0, -1, 0)
for _, item := range i {
if item.published.After(lastMonth) {
filtered = append(filtered, item)
}
}
return filtered
}
func main() {
var allItems items
for _, f := range feeds {
parsed, err := parseRSSFeed(f)
if err != nil {
log.Fatal(err)
}
for _, i := range parsed.Items {
markd, err := htmlToMarkdown(i.Content)
if err != nil {
log.Fatal(err)
}
var authors []string
for _, author := range i.Authors {
authors = append(authors, author.Name)
}
parsedLink, err := url.Parse(i.Link)
if err != nil {
log.Fatal(err)
}
newItem := item{
authors: authors,
content: markd,
description: i.Description,
link: i.Link,
host: parsedLink.Host,
published: i.PublishedParsed,
title: i.Title,
}
allItems = append(allItems, newItem)
}
}
for _, i := range allItems.LastMonth() {
i.Print()
}
}