This commit is contained in:
Christian Nieves
2023-07-03 18:23:23 -05:00
parent 8efe9263b1
commit 574a07495f
12 changed files with 148 additions and 40 deletions

3
extract/BUILD Normal file
View File

@ -0,0 +1,3 @@
package(
default_visibility = ["//visibility:public"],
)

18
extract/cmd/BUILD Normal file
View File

@ -0,0 +1,18 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "cmd_lib",
srcs = ["main.go"],
importpath = "github.com/squk/lotr/extract/cmd",
visibility = ["//visibility:private"],
deps = [
"//extract/types",
"@com_github_davecgh_go_spew//spew",
],
)
go_binary(
name = "cmd",
embed = [":cmd_lib"],
visibility = ["//visibility:public"],
)

30
extract/cmd/main.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/squk/lotr/extract/types"
"github.com/davecgh/go-spew/spew"
)
func main() {
fmt.Println("LOTR CARD PARSE")
// Open our jsonFile
jsonFile, err := os.Open("users.json")
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened users.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
c := []types.Card{}
json.Unmarshal(byteValue, &c)
spew.Dump(c)
}

8
extract/types/BUILD Normal file
View File

@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "types",
srcs = ["card.go"],
importpath = "github.com/squk/lotr/extract/types",
visibility = ["//visibility:public"],
)

35
extract/types/card.go Normal file
View File

@ -0,0 +1,35 @@
package extract
type Card struct {
PackCode string `json:"pack_code"`
PackName string `json:"pack_name"`
IsOfficial bool `json:"is_official"`
TypeCode string `json:"type_code"`
TypeName string `json:"type_name"`
SphereCode string `json:"sphere_code"`
SphereName string `json:"sphere_name"`
Position int `json:"position"`
Code string `json:"code"`
Name string `json:"name"`
Traits string `json:"traits"`
Text string `json:"text"`
Flavor string `json:"flavor"`
IsUnique bool `json:"is_unique"`
Threat int `json:"threat"`
Willpower int `json:"willpower"`
Attack int `json:"attack"`
Defense int `json:"defense"`
Health int `json:"health"`
Quantity int `json:"quantity"`
DeckLimit int `json:"deck_limit"`
Illustrator string `json:"illustrator"`
Octgnid string `json:"octgnid"`
HasErrata bool `json:"has_errata"`
URL string `json:"url"`
Imagesrc string `json:"imagesrc"`
Versions []struct {
SetName string `json:"set_name"`
Year string `json:"year"`
URL string `json:"url"`
} `json:"versions"`
}