mirror of
https://github.com/pikami/rss-dl.git
synced 2024-11-26 23:47:44 +00:00
Added info logging
This commit is contained in:
parent
07a977f4c8
commit
39d14eaf7a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
rss-dl
|
@ -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
10
helpers/logger.go
Normal file
@ -0,0 +1,10 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// LogInfo - Outputs message to stdout
|
||||
func LogInfo(str string) {
|
||||
fmt.Println(str)
|
||||
}
|
20
main.go
20
main.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user