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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
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()
|
fp := gofeed.NewParser()
|
||||||
|
LogInfo("Downloading " + args[0])
|
||||||
feed, _ := fp.ParseURL(args[0])
|
feed, _ := fp.ParseURL(args[0])
|
||||||
|
|
||||||
outputDir := ToCleanString(feed.Title)
|
outputDir := ToCleanString(feed.Title)
|
||||||
InitOutputDirectory(outputDir)
|
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 {
|
for _, item := range feed.Items {
|
||||||
itemOutputFilename := ToCleanString(
|
itemOutputFilename := ToCleanString(
|
||||||
item.PublishedParsed.Format("20060102") + "_" + item.Title)
|
item.PublishedParsed.Format("20060102") + "_" + item.Title)
|
||||||
itemOutputDir := outputDir + "/" + itemOutputFilename
|
itemOutputDir := outputDir + "/" + itemOutputFilename
|
||||||
|
|
||||||
if CheckIfExists(itemOutputDir) {
|
if CheckIfExists(itemOutputDir) {
|
||||||
|
fmt.Println("Item '" + item.Title + "' already downloaded, skipping")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogInfo("Downloading feed item '" + item.Title + "' to " + itemOutputDir)
|
||||||
InitOutputDirectory(itemOutputDir)
|
InitOutputDirectory(itemOutputDir)
|
||||||
|
|
||||||
|
itemDetailsPath := itemOutputDir + "/details.json"
|
||||||
|
LogInfo("Writing details to " + itemDetailsPath)
|
||||||
WriteToFile(
|
WriteToFile(
|
||||||
itemOutputDir+"/details.json",
|
itemDetailsPath,
|
||||||
GrabFeedItemJSON(item))
|
GrabFeedItemJSON(item))
|
||||||
|
|
||||||
|
itemImagePath := itemOutputDir + "/image" + filepath.Ext(item.Image.URL)
|
||||||
|
LogInfo("Downloading image to " + itemImagePath)
|
||||||
DownloadFile(
|
DownloadFile(
|
||||||
itemOutputDir+"/image"+filepath.Ext(item.Image.URL),
|
itemImagePath,
|
||||||
item.Image.URL)
|
item.Image.URL)
|
||||||
|
|
||||||
for _, enclosure := range item.Enclosures {
|
for _, enclosure := range item.Enclosures {
|
||||||
|
LogInfo("Downloading attachment '" + filepath.Base(enclosure.URL) + "'")
|
||||||
DownloadFile(
|
DownloadFile(
|
||||||
itemOutputDir+"/"+filepath.Base(enclosure.URL),
|
itemOutputDir+"/"+filepath.Base(enclosure.URL),
|
||||||
enclosure.URL)
|
enclosure.URL)
|
||||||
|
Loading…
Reference in New Issue
Block a user