@@ -17,15 +17,15 @@ import (
1717var URLRegex = xurls .Strict ()
1818
1919var options struct {
20- boardName string
21- pages uint
22- replies uint
20+ boardNames string
21+ pages uint
22+ replies uint
2323}
2424
2525func init () {
2626 flag .UintVar (& options .replies , "n" , 10 , "cutoff of number of replies on thread" )
2727 flag .UintVar (& options .pages , "p" , 1 , "number of pages/request to get/make" )
28- flag .StringVar (& options .boardName , "b" , "news" , "board name " )
28+ flag .StringVar (& options .boardNames , "b" , "news" , "comma-separated list of board names " )
2929}
3030
3131func main () {
@@ -45,23 +45,25 @@ func run() (string, error) {
4545 flag .Parse ()
4646 now := time .Now ()
4747 feed := & feeds.Feed {
48- Title : fmt .Sprintf ("4chan /%s/ threads" , options .boardName ),
49- Link : & feeds.Link {
50- Href : fmt .Sprintf ("https://boards.4channel.org/%s/" , options .boardName ),
51- },
52- Description : fmt .Sprintf (
53- "threads from /%s/ with more than %d comments" ,
54- options .boardName ,
55- options .replies ,
56- ),
57- Author : & feeds.Author {Name : "Anon" },
58- Created : now ,
48+ Title : fmt .Sprintf ("4chan threads from multiple boards" ),
49+ Link : & feeds.Link {Href : "https://boards.4channel.org/" },
50+ Description : fmt .Sprintf ("threads from multiple boards with more than %d comments" , options .replies ),
51+ Author : & feeds.Author {Name : "Anon" },
52+ Created : now ,
5953 }
60- threads , err := getThreads (options .boardName , options .pages )
61- if err != nil {
62- return "" , err
54+
55+ boards := strings .Split (options .boardNames , "," )
56+ var allItems []* feeds.Item
57+ for _ , board := range boards {
58+ threads , err := getThreads (board , options .pages )
59+ if err != nil {
60+ return "" , err
61+ }
62+ items := processThreads (threads , board )
63+ allItems = append (allItems , items ... )
6364 }
64- feed .Items = processThreads (threads )
65+
66+ feed .Items = allItems
6567 atom , err := feed .ToAtom ()
6668 if err != nil {
6769 return "" , err
@@ -80,24 +82,24 @@ func getThreads(board string, pages uint) (threads []*api.Thread, err error) {
8082 return
8183}
8284
83- func processThreads (threads []* api.Thread ) []* feeds.Item {
85+ func processThreads (threads []* api.Thread , board string ) []* feeds.Item {
8486 var items []* feeds.Item
8587 for _ , thread := range threads {
8688 if thread .Replies () < int (options .replies ) {
8789 continue
8890 }
89- item := processPost (thread .OP )
91+ item := processPost (thread .OP , board )
9092 item .Title = fmt .Sprintf ("[%3d] %s" , min (999 , thread .Replies ()), item .Title )
9193 items = append (items , item )
9294 }
9395 return items
9496}
9597
96- func processPost (post * api.Post ) * feeds.Item {
98+ func processPost (post * api.Post , board string ) * feeds.Item {
9799 item := & feeds.Item {}
98100 item .Title = getTitle (post )
99101 item .Link = & feeds.Link {
100- Href : fmt .Sprintf ("https://boards.4channel.org/%s/thread/%d/" , options . boardName , post .Id ),
102+ Href : fmt .Sprintf ("https://boards.4channel.org/%s/thread/%d/" , board , post .Id ),
101103 }
102104 item .Description = anchorize (strings .ReplaceAll (post .Comment , "<wbr>" , "" ))
103105 if post .File != nil {
0 commit comments