CSV for lotr-lcg-set-generator
This commit is contained in:
@ -14,7 +14,7 @@ go_library(
|
|||||||
importpath = "github.com/squk/lotr/cmd/beornextract",
|
importpath = "github.com/squk/lotr/cmd/beornextract",
|
||||||
deps = [
|
deps = [
|
||||||
"//cmd/beornextract/types",
|
"//cmd/beornextract/types",
|
||||||
"@com_github_davecgh_go_spew//spew",
|
"@com_github_grokify_html_strip_tags_go//:html-strip-tags-go",
|
||||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||||
"github.com/davecgh/go-spew/spew"
|
strip "github.com/grokify/html-strip-tags-go"
|
||||||
"github.com/squk/lotr/cmd/beornextract/types"
|
"github.com/squk/lotr/cmd/beornextract/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,19 +36,81 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open our jsonFile
|
// Open our jsonFile
|
||||||
// jsonFile, err := os.Open("cmd/beornextract/data/Bot.Cards.json")
|
jsonFile, err := os.Open("cmd/beornextract/data/Bot.Cards.json")
|
||||||
jsonFile, err := bazel.Runfile("cmd/beornextract/data/Bot.Cards.json")
|
// jsonFile, err := bazel.Runfile("cmd/beornextract/data/Bot.Cards.json")
|
||||||
// if we os.Open returns an error then handle it
|
// if we os.Open returns an error then handle it
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Successfully Opened users.json")
|
|
||||||
// defer the closing of our jsonFile so that we can parse it later on
|
// defer the closing of our jsonFile so that we can parse it later on
|
||||||
defer jsonFile.Close()
|
defer jsonFile.Close()
|
||||||
|
|
||||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||||
c := []types.HallOfBeornCard{}
|
cards := []types.HallOfBeornCard{}
|
||||||
json.Unmarshal(byteValue, &c)
|
json.Unmarshal(byteValue, &cards)
|
||||||
spew.Dump(c)
|
|
||||||
|
// Open a file for writing
|
||||||
|
csvFile, err := os.Create("/Users/christian/Downloads/lotr-lcg-set-generator.csv")
|
||||||
|
defer csvFile.Close()
|
||||||
|
if err != nil {
|
||||||
|
// Handle error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a writer
|
||||||
|
w := csv.NewWriter(csvFile)
|
||||||
|
|
||||||
|
// Write some rows
|
||||||
|
for _, card := range cards {
|
||||||
|
if card.EncounterSet != "" {
|
||||||
|
continue // skip non=player cards
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(
|
||||||
|
[]string{
|
||||||
|
card.Octgnid,
|
||||||
|
"", // hidden
|
||||||
|
"", // hidden
|
||||||
|
card.EncounterSet,
|
||||||
|
strconv.Itoa(card.Position),
|
||||||
|
strconv.Itoa(card.Quantity),
|
||||||
|
card.Name,
|
||||||
|
fmt.Sprintf(
|
||||||
|
"%t",
|
||||||
|
card.IsUnique,
|
||||||
|
),
|
||||||
|
card.TypeName,
|
||||||
|
card.SphereName,
|
||||||
|
card.Traits,
|
||||||
|
extractKeywords(card.Text),
|
||||||
|
card.Cost,
|
||||||
|
card.EngagementCost,
|
||||||
|
strconv.Itoa(card.Threat),
|
||||||
|
strconv.Itoa(card.Willpower),
|
||||||
|
strconv.Itoa(card.Attack),
|
||||||
|
strconv.Itoa(card.Defense),
|
||||||
|
strconv.Itoa(card.Health),
|
||||||
|
"", // Quest Points
|
||||||
|
"", // Victory Points
|
||||||
|
"", // Special Icon
|
||||||
|
transformText(card.Name, card.Text),
|
||||||
|
card.Flavor,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the writer
|
||||||
|
w.Flush()
|
||||||
|
// spew.Dump(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func transformText(name, text string) string {
|
||||||
|
return strip.StripTags(
|
||||||
|
strings.ReplaceAll(text, name, "[name]"), // insert name tag
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractKeywords(text string) string {
|
||||||
|
pattern := regexp.MustCompile(`((?:(?:[A-Z][a-z]+(\.|\s[0-9]+\.)\s)+))`)
|
||||||
|
return strings.TrimSpace(pattern.FindString(text))
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,37 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type HallOfBeornCard struct {
|
type HallOfBeornCard struct {
|
||||||
PackCode string `json:"pack_code"`
|
PackCode string `json:"pack_code,omitempty"`
|
||||||
PackName string `json:"pack_name"`
|
PackName string `json:"pack_name,omitempty"`
|
||||||
IsOfficial bool `json:"is_official"`
|
IsOfficial bool `json:"is_official,omitempty"`
|
||||||
TypeCode string `json:"type_code"`
|
TypeCode string `json:"type_code,omitempty"`
|
||||||
TypeName string `json:"type_name"`
|
TypeName string `json:"type_name,omitempty"`
|
||||||
SphereCode string `json:"sphere_code"`
|
SphereCode string `json:"sphere_code,omitempty"`
|
||||||
SphereName string `json:"sphere_name"`
|
SphereName string `json:"sphere_name,omitempty"`
|
||||||
Position int `json:"position"`
|
Position int `json:"position,omitempty"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code,omitempty"`
|
||||||
Name string `json:"name"`
|
Cost string `json:"cost,omitempty"`
|
||||||
Traits string `json:"traits"`
|
Name string `json:"name,omitempty"`
|
||||||
Text string `json:"text"`
|
Traits string `json:"traits,omitempty"`
|
||||||
Flavor string `json:"flavor"`
|
Text string `json:"text,omitempty"`
|
||||||
IsUnique bool `json:"is_unique"`
|
Flavor string `json:"flavor,omitempty"`
|
||||||
Threat int `json:"threat"`
|
IsUnique bool `json:"is_unique,omitempty"`
|
||||||
Willpower int `json:"willpower"`
|
Threat int `json:"threat,omitempty"`
|
||||||
Attack int `json:"attack"`
|
Willpower int `json:"willpower,omitempty"`
|
||||||
Defense int `json:"defense"`
|
Attack int `json:"attack,omitempty"`
|
||||||
Health int `json:"health"`
|
Defense int `json:"defense,omitempty"`
|
||||||
Quantity int `json:"quantity"`
|
Health int `json:"health,omitempty"`
|
||||||
DeckLimit int `json:"deck_limit"`
|
Quantity int `json:"quantity,omitempty"`
|
||||||
Illustrator string `json:"illustrator"`
|
DeckLimit int `json:"deck_limit,omitempty"`
|
||||||
Octgnid string `json:"octgnid"`
|
Illustrator string `json:"illustrator,omitempty"`
|
||||||
HasErrata bool `json:"has_errata"`
|
Octgnid string `json:"octgnid,omitempty"`
|
||||||
URL string `json:"url"`
|
HasErrata bool `json:"has_errata,omitempty"`
|
||||||
Imagesrc string `json:"imagesrc"`
|
URL string `json:"url,omitempty"`
|
||||||
|
Imagesrc string `json:"imagesrc,omitempty"`
|
||||||
|
|
||||||
|
EncounterSet string `json:"encounter_set,omitempty"`
|
||||||
|
EngagementCost string `json:"engagement_cost,omitempty"`
|
||||||
|
ThreatStrength int `json:"threat_strength,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NormalizedCard struct {
|
type NormalizedCard struct{}
|
||||||
}
|
|
||||||
|
7
deps.bzl
7
deps.bzl
@ -30,6 +30,13 @@ def go_dependencies():
|
|||||||
sum = "h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=",
|
sum = "h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=",
|
||||||
version = "v1.5.2",
|
version = "v1.5.2",
|
||||||
)
|
)
|
||||||
|
go_repository(
|
||||||
|
name = "com_github_grokify_html_strip_tags_go",
|
||||||
|
build_file_proto_mode = "disable_global",
|
||||||
|
importpath = "github.com/grokify/html-strip-tags-go",
|
||||||
|
sum = "h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=",
|
||||||
|
version = "v0.0.1",
|
||||||
|
)
|
||||||
|
|
||||||
go_repository(
|
go_repository(
|
||||||
name = "com_github_mattn_go_sqlite3",
|
name = "com_github_mattn_go_sqlite3",
|
||||||
|
1
go.mod
1
go.mod
@ -6,5 +6,6 @@ require github.com/davecgh/go-spew v1.1.1
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bazelbuild/rules_go v0.41.0 // indirect
|
github.com/bazelbuild/rules_go v0.41.0 // indirect
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -2,5 +2,7 @@ github.com/bazelbuild/rules_go v0.41.0 h1:JzlRxsFNhlX+g4drDRPhIaU5H5LnI978wdMJ0v
|
|||||||
github.com/bazelbuild/rules_go v0.41.0/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
|
github.com/bazelbuild/rules_go v0.41.0/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
||||||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
||||||
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
|
Reference in New Issue
Block a user