aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 00:30:35 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 00:30:35 +0300
commit18daf268e2e334649c0e07f9c2117b91dab4bae5 (patch)
treebd117821fa7c4af73aa8964fbf7c6ca5328c8304 /main.go
parentd77644791137a22182a7d509d4457efb60e46e66 (diff)
downloadradiorus-rss-18daf268e2e334649c0e07f9c2117b91dab4bae5.tar.gz
radiorus-rss-18daf268e2e334649c0e07f9c2117b91dab4bae5.zip
decouple feed description and output
Diffstat (limited to 'main.go')
-rw-r--r--main.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/main.go b/main.go
index d81ea48..75750aa 100644
--- a/main.go
+++ b/main.go
@@ -22,6 +22,7 @@ import (
"net/http"
"regexp"
"strconv"
+ "strings"
"time"
"github.com/gorilla/feeds"
@@ -64,16 +65,22 @@ func main() {
}
populateFeed(feed, page)
+ describeFeed(feed)
describeEpisodes(feed)
feed.Created = time.Now()
+ outputFile := outputPath + "radiorus-" + programNumber + ".rss"
+
+ writeFeed(feed, outputFile)
+}
+
+func writeFeed(feed *feeds.Feed, filename string) {
rss, err := feed.ToRss()
if err != nil {
log.Fatal(err)
}
- outputFile := outputPath + "radiorus-" + programNumber + ".rss"
output := []byte(rss)
- if err := ioutil.WriteFile(outputFile, output, 0644); err != nil {
+ if err := ioutil.WriteFile(filename, output, 0644); err != nil {
log.Fatal(err)
}
}
@@ -90,12 +97,6 @@ func populateFeed(feed *feeds.Feed, page []byte) {
episodes := episodeRe.FindAll(page, -1)
- programAboutUrl := "http://www.radiorus.ru/brand/" + programNumber + "/about"
- programAboutPage := getPage(programAboutUrl)
- programAbout := programAboutRe.FindSubmatch(programAboutPage)[1]
- re := regexp.MustCompile(`<(.+?)?>`)
- feed.Description = string(re.ReplaceAll(programAbout, []byte(``)))
-
badFeed := false
for _, episode := range episodes {
@@ -140,6 +141,14 @@ func populateFeed(feed *feeds.Feed, page []byte) {
}
}
+func describeFeed(feed *feeds.Feed) {
+ programAboutUrl := strings.TrimSuffix(feed.Link.Href, "episodes") + "about"
+ programAboutPage := getPage(programAboutUrl)
+ programAbout := programAboutRe.FindSubmatch(programAboutPage)[1]
+ re := regexp.MustCompile(`<(.+?)?>`)
+ feed.Description = string(re.ReplaceAll(programAbout, []byte(``)))
+}
+
func describeEpisodes(feed *feeds.Feed) {
for _, item := range feed.Items {
page := getPage(item.Link.Href)