Added info logging

This commit is contained in:
Pijus Kamandulis 2019-04-20 21:48:28 +03:00
parent 07a977f4c8
commit 39d14eaf7a
4 changed files with 28 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
rss-dl

View File

@ -39,9 +39,5 @@ func CheckIfExists(path string) bool {
return false
}
if _, err := os.Stat(path); !os.IsNotExist(err) {
return false
}
return true
}

10
helpers/logger.go Normal file
View File

@ -0,0 +1,10 @@
package helpers
import (
"fmt"
)
// LogInfo - Outputs message to stdout
func LogInfo(str string) {
fmt.Println(str)
}

20
main.go
View File

@ -20,29 +20,43 @@ func main() {
}
fp := gofeed.NewParser()
LogInfo("Downloading " + args[0])
feed, _ := fp.ParseURL(args[0])
outputDir := ToCleanString(feed.Title)
InitOutputDirectory(outputDir)
WriteToFile(outputDir+"/feed_details.json", GrabFeedDetailsJSON(feed))
feedInfoPath := outputDir + "/feed_details.json"
LogInfo("Writing feed details as JSON to " + feedInfoPath)
WriteToFile(feedInfoPath, GrabFeedDetailsJSON(feed))
for _, item := range feed.Items {
itemOutputFilename := ToCleanString(
item.PublishedParsed.Format("20060102") + "_" + item.Title)
itemOutputDir := outputDir + "/" + itemOutputFilename
if CheckIfExists(itemOutputDir) {
fmt.Println("Item '" + item.Title + "' already downloaded, skipping")
continue
}
LogInfo("Downloading feed item '" + item.Title + "' to " + itemOutputDir)
InitOutputDirectory(itemOutputDir)
itemDetailsPath := itemOutputDir + "/details.json"
LogInfo("Writing details to " + itemDetailsPath)
WriteToFile(
itemOutputDir+"/details.json",
itemDetailsPath,
GrabFeedItemJSON(item))
itemImagePath := itemOutputDir + "/image" + filepath.Ext(item.Image.URL)
LogInfo("Downloading image to " + itemImagePath)
DownloadFile(
itemOutputDir+"/image"+filepath.Ext(item.Image.URL),
itemImagePath,
item.Image.URL)
for _, enclosure := range item.Enclosures {
LogInfo("Downloading attachment '" + filepath.Base(enclosure.URL) + "'")
DownloadFile(
itemOutputDir+"/"+filepath.Base(enclosure.URL),
enclosure.URL)