all repos — honk @ 79bf63e34ccb38349f62e00285c19515c5edf739

my fork of honk

syndicate.go (view raw)

 1package main
 2
 3import (
 4	"bytes"
 5	notrand "math/rand"
 6	"strings"
 7	"time"
 8
 9	"github.com/mmcdole/gofeed"
10)
11
12func syndicate(user *WhatAbout, url string) {
13	data, err := fetchsome(url)
14	if err != nil {
15		dlog.Printf("error fetching feed: %s", err)
16		return
17	}
18	parser := gofeed.NewParser()
19	rss, err := parser.Parse(bytes.NewReader(data))
20	if err != nil {
21		dlog.Printf("error parsing feed: %s", err)
22		return
23	}
24	reverseItems(rss.Items)
25	for _, item := range rss.Items {
26		dlog.Printf("link: %s", item.Link)
27		grabhonk(user, item.Link)
28	}
29}
30
31func syndicator() {
32	for {
33		dur := 8 * time.Hour
34		dur += time.Duration(notrand.Int63n(int64(dur / 4)))
35		time.Sleep(dur)
36		users := allusers()
37		for _, ui := range users {
38			user, _ := butwhatabout(ui.Username)
39			honkers := gethonkers(user.ID)
40			for _, h := range honkers {
41				if strings.HasSuffix(h.XID, ".rss") {
42					syndicate(user, h.XID)
43				}
44			}
45		}
46	}
47}
48
49func reverseItems(items []*gofeed.Item) {
50	for i, j := 0, len(items)-1; i < j; i, j = i+1, j-1 {
51		items[i], items[j] = items[j], items[i]
52	}
53}