Compare commits

..

3 Commits

Author SHA1 Message Date
8cf51e1004 Added support for atom feeds
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
2022-08-08 07:05:03 +01:00
86f826b3e4 Merge branch 'master' of https://git.cluster.fun/AverageMarcus/feed-fetcher 2021-03-21 09:45:35 +00:00
367e6909c3 Added logo to readme 2021-03-21 09:45:25 +00:00
3 changed files with 6 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
# feed-fetcher ![feed-fetcher](logo.png)
Returns the RSS feed associated with the given URL Returns the RSS feed associated with the given URL

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

10
main.go
View File

@@ -79,7 +79,7 @@ func getFeeds(requestURL string) ([]string, int) {
} else if err != nil && err == gofeed.ErrFeedTypeNotDetected { } else if err != nil && err == gofeed.ErrFeedTypeNotDetected {
res, err := http.Get(requestURL) res, err := http.Get(requestURL)
if err != nil { if err != nil {
fmt.Println("Failed to fetch URL") fmt.Printf("Failed to fetch URL %s", requestURL)
return feeds, fiber.StatusInternalServerError return feeds, fiber.StatusInternalServerError
} }
defer res.Body.Close() defer res.Body.Close()
@@ -95,9 +95,9 @@ func getFeeds(requestURL string) ([]string, int) {
return feeds, fiber.StatusInternalServerError return feeds, fiber.StatusInternalServerError
} }
matches := doc.Find(`[rel="alternate"][type="application/rss+xml"]`) matches := doc.Find(`[rel="alternate"][type="application/rss+xml"],[rel="alternate"][type="application/atom+xml"]`)
if matches.Length() == 0 { if matches.Length() == 0 {
fmt.Println("No RSS feeds found on page") fmt.Printf("No RSS feeds found on page %s\n", requestURL)
return feeds, fiber.StatusNotFound return feeds, fiber.StatusNotFound
} }
@@ -106,10 +106,10 @@ func getFeeds(requestURL string) ([]string, int) {
}) })
if matches.Length() > 1 { if matches.Length() > 1 {
fmt.Println("Multiple feeds found on page") fmt.Printf("Multiple RSS feed found on page %s\n", requestURL)
return feeds, fiber.StatusMultipleChoices return feeds, fiber.StatusMultipleChoices
} else { } else {
fmt.Println("Feed found on page") fmt.Printf("Single RSS feed found on page %s\n", requestURL)
return feeds, fiber.StatusTemporaryRedirect return feeds, fiber.StatusTemporaryRedirect
} }
} else if err != nil { } else if err != nil {