コード例 #1
0
func loopFeed(feed *rss.Feed, url string, chatid int) {
	go func() {
		interval := 7
		stopRssLoop[strconv.Itoa(chatid)+":"+url] = make(chan bool)

		firstLoop := true
		t := time.Tick(time.Minute*time.Duration(interval-1) +
			time.Second*time.Duration(rand.Intn(120)))

	Loop:
		for {
			select {
			case <-stopRssLoop[strconv.Itoa(chatid)+":"+url]:
				break Loop
			case <-t:
				if firstLoop {
					time.Sleep(time.Duration(rand.Intn(interval)) * time.Minute)
					firstLoop = false
				}
				if err := feed.Fetch(url, charsetReader); err != nil {
					loge.Warningf("failed to fetch rss, "+
						"retry in 3 seconds... [ %s ]", url)
					time.Sleep(time.Second * 3)
					continue
				}
			}
		}

	}()
}
func chanHandler(feed *rss.Feed, newchannels []*rss.Channel) {
	fmt.Printf("%d new channel(s) in %s\n", len(newchannels), feed.Url)
	fmt.Printf("%d seconds between updates\n", feed.SecondsTillUpdate())
}