all repos — honk @ e8b102066e9d009f3d1667aecaaa7ffe351eb549

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