TheMathemagicians/sevenkeys/cmd/importcards/main.go

32 lines
541 B
Go
Raw Normal View History

2024-04-28 14:13:47 +00:00
package main
import (
2024-05-19 16:11:42 +00:00
"encoding/json"
"io/ioutil"
2024-05-19 14:01:18 +00:00
"log"
2024-04-28 14:13:47 +00:00
"sevenkeys/database/operations"
2024-05-19 14:01:18 +00:00
"sevenkeys/scryfall/types"
2024-04-28 14:13:47 +00:00
)
2024-05-19 14:01:18 +00:00
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
2024-04-28 14:13:47 +00:00
func main() {
2024-05-19 14:01:18 +00:00
if updatedAtTimestamp.After(cachedFileTimestamp) {
} else {
log.Printf("Bulk data has not been updated. Skipping download.")
}
2024-05-19 16:11:42 +00:00
var allCards []types.Card
2024-05-20 16:33:40 +00:00
allCardsBytes, err := ioutil.ReadFile(ALL_CARDS_CACHE_FILENAME)
2024-05-19 16:11:42 +00:00
check(err)
err = json.Unmarshal(allCardsBytes, &allCards)
check(err)
2024-05-19 14:01:18 +00:00
2024-04-28 14:13:47 +00:00
operations.InsertCards(db, allCards)
}