Skip to content

Commit

Permalink
julia: added plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
haarts committed Mar 3, 2017
1 parent 3641016 commit e3821c1
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions plugins/julialang_news/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import "C"
import (
"log"
"regexp"

"github.com/SlyMarbo/rss"
)

type Feed struct {
URL string
ItemHandler func(*rss.Item) string
}

func List() []Feed {
return []Feed{
Feed{
URL: "http://www.juliabloggers.com/feed/",
ItemHandler: blogItem,
},
Feed{
URL: "https://news.ycombinator.com/rss",
ItemHandler: hnItem,
},
Feed{
URL: "https://www.reddit.com/r/julia.rss",
ItemHandler: redditItem,
},
}
}

func hnItem(item *rss.Item) string {
if match, _ := regexp.MatchString(`\w Julia( |$|\.)`, item.Title); match {
short_title := item.Title
if len(short_title) > 100 {
short_title = short_title[:99] + "…"
}
return short_title + " " + item.Link + " #hackernews"
} else {
log.Printf("Ignoring Hackernews item: %s", item.Title)
return ""
}

}

func blogItem(item *rss.Item) string {
short_title := item.Title
if len(short_title) > 100 {
short_title = short_title[:99] + "…"
}
return short_title + " " + item.Link + " #juliabloggers"
}

func redditItem(item *rss.Item) string {
re := regexp.MustCompile(`([^"]+)">\[link\]`)
matches := re.FindStringSubmatch(item.Content)
if len(matches) == 2 {
short_title := item.Title
if len(short_title) > 100 {
short_title = short_title[:99] + "…"
}
return short_title + " " + matches[1] + " #reddit"
}
return ""
}

0 comments on commit e3821c1

Please sign in to comment.