diff options
author | Evgeny Kuznetsov <evgeny@kuznetsov.md> | 2020-01-28 00:30:35 +0300 |
---|---|---|
committer | Evgeny Kuznetsov <evgeny@kuznetsov.md> | 2020-01-28 00:30:35 +0300 |
commit | 18daf268e2e334649c0e07f9c2117b91dab4bae5 (patch) | |
tree | bd117821fa7c4af73aa8964fbf7c6ca5328c8304 /main.go | |
parent | d77644791137a22182a7d509d4457efb60e46e66 (diff) | |
download | radiorus-rss-18daf268e2e334649c0e07f9c2117b91dab4bae5.tar.gz radiorus-rss-18daf268e2e334649c0e07f9c2117b91dab4bae5.zip |
decouple feed description and output
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -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) |