From 9fa8bb563fd926ef5d3010dad9291ad902cb2d94 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 21 May 2024 15:15:58 +0100 Subject: [PATCH] Unmarshal card data into slice --- sevenkeys/main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sevenkeys/main.go b/sevenkeys/main.go index 886d859..324a629 100644 --- a/sevenkeys/main.go +++ b/sevenkeys/main.go @@ -2,7 +2,9 @@ package main import ( "database/sql" + "encoding/json" "io" + "io/ioutil" "log" "net/http" "os" @@ -157,6 +159,17 @@ func main() { log.Printf("Bulk data has not been updated. Skipping download.") } - // Unmarshal cached file into Golang struct - // Import cards into database + log.Printf("Unmarsaling file into slice...") + allCardsBytes, err := ioutil.ReadFile(ALL_CARDS_CACHE_FILENAME) + check(err) + + var allCards []types.Card + err = json.Unmarshal(allCardsBytes, &allCards) + check(err) + log.Printf("Unmarshaled file.") + + log.Printf("Importing card data into database...") + err = operations.InsertCards(db, allCards) + check(err) + log.Printf("Imported card data.") }