all repos — honk @ a3110723adad4a749c7aa75c24f41254bcb71a62

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		var final string
27		dlog.Printf("link: %s", item.Link)
28		j, err := GetJunkTimeout(user.ID, item.Link, fastTimeout*time.Second, &final)
29		if err != nil {
30			dlog.Printf("unable to fetch link: %s", err)
31			continue
32		}
33		xonksaver(user, j, originate(final))
34	}
35}
36
37func syndicator() {
38	for {
39		dur := 12 * time.Hour
40		dur += time.Duration(notrand.Int63n(int64(dur / 4)))
41		time.Sleep(dur)
42		users := allusers()
43		for _, ui := range users {
44			user, _ := butwhatabout(ui.Username)
45			honkers := gethonkers(user.ID)
46			for _, h := range honkers {
47				if strings.HasSuffix(h.XID, ".rss") {
48					syndicate(user, h.XID)
49				}
50			}
51		}
52	}
53}
54
55func reverseItems(items []*gofeed.Item) {
56	for i, j := 0, len(items)-1; i < j; i, j = i+1, j-1 {
57		items[i], items[j] = items[j], items[i]
58	}
59}