Skip to content

Commit 91861af

Browse files
committed
add multiple boards parsing with -b
1 parent ced6174 commit 91861af

File tree

3 files changed

+392
-43
lines changed

3 files changed

+392
-43
lines changed

.github/workflows/create-feed.yml

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
name: Generate 4chan RSS Feed
1+
name: Generate RSS feed
22

33
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
48
schedule:
5-
- cron: "*/15 * * * *" # Runs every 15 minutes
6-
workflow_dispatch: # Allows manual trigger
9+
- cron: '*/30 * * * *' # Runs every 30 minutes
710

811
jobs:
9-
generate-rss:
12+
build:
1013
runs-on: ubuntu-latest
14+
1115
steps:
12-
- name: Checkout repository
13-
uses: actions/checkout@v4
16+
- name: Checkout repository
17+
uses: actions/checkout@v2
1418

15-
- name: Set up Go
16-
uses: actions/setup-go@v5
17-
with:
18-
go-version: "1.21"
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: '1.18'
1923

20-
- name: Install Dependencies
21-
run: go mod tidy
24+
- name: Run Go script
25+
run: go run main.go -b news,g,vg -n 30 -p 1
2226

23-
- name: Generate RSS Feed
24-
run: go run main.go -b g -n 30 -p 1
27+
- name: Commit updated RSS feed
28+
run: |
29+
git config --global user.name 'GitHub Actions'
30+
git config --global user.email 'actions@github.com'
2531
26-
- name: Commit and Push RSS Feed
27-
run: |
28-
git config --global user.name "github-actions[bot]"
29-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
32+
# Check if there are changes to rss.xml
33+
git diff --exit-code rss.xml || {
3034
git add rss.xml
31-
git commit -m "update rss feed" || echo "no changes to commit"
32-
git push
35+
git commit -m "auto: update rss feed"
36+
git push origin master
37+
}
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

main.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import (
1717
var URLRegex = xurls.Strict()
1818

1919
var options struct {
20-
boardName string
21-
pages uint
22-
replies uint
20+
boardNames string
21+
pages uint
22+
replies uint
2323
}
2424

2525
func 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

3131
func 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

Comments
 (0)