summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-12-21 00:38:25 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-12-21 00:38:25 +0100
commit75bec51affee1f01d107e68b38180c9d5d5edae0 (patch)
tree05f7d5403be11b4c81ad397335465c71b62cb9c5
parent432d01e3872d050663379006a7e66dc2932a89d7 (diff)
Split feeds
-rw-r--r--feeds.go61
-rw-r--r--main.go2
-rw-r--r--rss.go66
3 files changed, 66 insertions, 63 deletions
diff --git a/feeds.go b/feeds.go
new file mode 100644
index 0000000..9e6412e
--- /dev/null
+++ b/feeds.go
@@ -0,0 +1,61 @@
+package main
+
+import "time"
+
+var Feeds = []Feed{
+ {
+ Name: "LOR News",
+ URL: `https://www.linux.org.ru/section-rss.jsp?section=1`,
+ Every: time.Hour,
+ },
+ {
+ Name: "LOR Forum",
+ URL: `https://www.linux.org.ru/section-rss.jsp?section=2&filter=tech`,
+ Every: time.Minute,
+ },
+ {
+ Name: "LOR Gallery",
+ URL: `https://www.linux.org.ru/section-rss.jsp?section=3`,
+ Every: 2 * time.Hour,
+ },
+ {
+ Name: "LOR Polls",
+ URL: `https://www.linux.org.ru/section-rss.jsp?section=5`,
+ Every: 2 * time.Hour,
+ },
+ {
+ Name: "OpenNET",
+ URL: `http://www.opennet.ru/opennews/opennews_all_noadv.rss`,
+ Every: 4 * time.Hour,
+ },
+ {
+ Name: "Undeadly",
+ URL: `http://undeadly.org/cgi?action=rss`,
+ Every: 2 * time.Hour,
+ },
+ {
+ Name: "Kernel",
+ URL: `https://www.kernel.org/feeds/kdist.xml`,
+ Every: 6 * time.Hour,
+ },
+ {
+ Name: "Ted Unangst",
+ URL: `http://www.tedunangst.com/flak/rss`,
+ Every: 6 * time.Hour,
+ },
+ {
+ Name: "Calomel",
+ URL: `https://calomel.org/calomel_rss.xml`,
+ Every: 6 * time.Hour,
+ },
+ {
+ Name: "Golang News",
+ URL: `https://golangnews.com/index.xml`,
+ Every: 6 * time.Hour,
+ },
+ {
+ Name: "Golang Weekly",
+ URL: `http://golangweekly.com/rss/1fg21ahk`,
+ Every: 6 * time.Hour,
+ },
+}
diff --git a/main.go b/main.go
index da2f50b..cd1d751 100644
--- a/main.go
+++ b/main.go
@@ -49,7 +49,6 @@ func discon(c chan struct{}) irc.HandlerFunc {
}
func privmsg(n, k chan string, room string) irc.HandlerFunc {
- go watchNews(n) // TODO shall it be there?
l := links(n)
return func(conn *irc.Conn, line *irc.Line) {
t := line.Text()
@@ -71,6 +70,7 @@ func main() {
done := make(chan struct{})
n := notify(c, *room)
k := kicker(c, *room)
+ go Watch(n, Feeds) // TODO shall it be there?
// setup event handler
handler := []struct {
diff --git a/rss.go b/rss.go
index 741b81d..6f5239b 100644
--- a/rss.go
+++ b/rss.go
@@ -14,64 +14,6 @@ type Feed struct {
Every time.Duration
}
-var Feeds = []Feed{
- {
- Name: "LOR News",
- URL: `https://www.linux.org.ru/section-rss.jsp?section=1`,
- Every: time.Hour,
- },
- {
- Name: "LOR Forum",
- URL: `https://www.linux.org.ru/section-rss.jsp?section=2&filter=tech`,
- Every: time.Minute,
- },
- {
- Name: "LOR Gallery",
- URL: `https://www.linux.org.ru/section-rss.jsp?section=3`,
- Every: 2 * time.Hour,
- },
- {
- Name: "LOR Polls",
- URL: `https://www.linux.org.ru/section-rss.jsp?section=5`,
- Every: 2 * time.Hour,
- },
- {
- Name: "OpenNET",
- URL: `http://www.opennet.ru/opennews/opennews_all_noadv.rss`,
- Every: 4 * time.Hour,
- },
- {
- Name: "Undeadly",
- URL: `http://undeadly.org/cgi?action=rss`,
- Every: 2 * time.Hour,
- },
- {
- Name: "Kernel",
- URL: `https://www.kernel.org/feeds/kdist.xml`,
- Every: 6 * time.Hour,
- },
- {
- Name: "Ted Unangst",
- URL: `http://www.tedunangst.com/flak/rss`,
- Every: 6 * time.Hour,
- },
- {
- Name: "Calomel",
- URL: `https://calomel.org/calomel_rss.xml`,
- Every: 6 * time.Hour,
- },
- {
- Name: "Golang News",
- URL: `https://golangnews.com/index.xml`,
- Every: 6 * time.Hour,
- },
- {
- Name: "Golang Weekly",
- URL: `http://golangweekly.com/rss/1fg21ahk`,
- Every: 6 * time.Hour,
- },
-}
-
type News struct {
Feed
rss.Item
@@ -88,7 +30,7 @@ func (n News) String() string {
return s
}
-func (f Feed) Watch(news chan News) {
+func (f Feed) watch(news chan News) {
ticker := time.NewTicker(f.Every)
defer ticker.Stop()
for t := range ticker.C {
@@ -106,10 +48,10 @@ func (f Feed) Watch(news chan News) {
}
}
-func watchNews(msg chan string) {
+func Watch(msg chan string, feeds []Feed) {
news := make(chan News)
- for _, feed := range Feeds {
- go feed.Watch(news)
+ for _, feed := range feeds {
+ go feed.watch(news)
}
for n := range news {
msg <- fmt.Sprint(n)