Initial commit still with some hardcoded things
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user