Files

39 lines
667 B
Go

package cmd
import (
"log"
"os"
scraper "github.com/ESilva15/PTInvCertSWDB/scraper"
"github.com/spf13/cobra"
)
func scrapeAction(cmd *cobra.Command, args []string) {
list := scraper.Scrape()
file, err := os.OpenFile("./swdb.yaml", os.O_CREATE|os.O_RDWR, 0744)
if err != nil {
log.Fatal("Failed to open DB file:", err)
}
n, err := file.Write(list.ToYAML())
if err != nil {
log.Fatal("Error writing data to db file:", err)
}
log.Println("Succesfully wrote ", n, "to db file")
}
// shelf
var scrapeCMD = &cobra.Command{
Use: "scrape",
Short: "",
Long: ``,
Args: nil,
Run: scrapeAction,
}
func init() {
rootCmd.AddCommand(scrapeCMD)
}