Convert HallOfBeornDump to CSV for ALEP pipeline
This commit is contained in:
@ -15,6 +15,7 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//cmd/beornextract/types",
|
"//cmd/beornextract/types",
|
||||||
"@com_github_grokify_html_strip_tags_go//:html-strip-tags-go",
|
"@com_github_grokify_html_strip_tags_go//:html-strip-tags-go",
|
||||||
|
"@com_github_jessevdk_go_flags//:go_default_library",
|
||||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -14,10 +14,24 @@ import (
|
|||||||
|
|
||||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||||
strip "github.com/grokify/html-strip-tags-go"
|
strip "github.com/grokify/html-strip-tags-go"
|
||||||
|
"github.com/jessevdk/go-flags"
|
||||||
"github.com/squk/lotr/cmd/beornextract/types"
|
"github.com/squk/lotr/cmd/beornextract/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
RawConversion bool `short:"r" long:"raw" description:"Enable to keep the original text from HallOfBeorn dump. Enable to prep for ALEP pipeline."`
|
||||||
|
}
|
||||||
|
|
||||||
|
var opts = Options{
|
||||||
|
RawConversion: false,
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
_, err := flags.ParseArgs(&opts, os.Args)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("LOTR CARD PARSE")
|
fmt.Println("LOTR CARD PARSE")
|
||||||
f, err := bazel.Runfile(".")
|
f, err := bazel.Runfile(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,8 +50,8 @@ 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 := os.Open("cmd/beornextract/data/Export.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)
|
||||||
@ -82,7 +96,7 @@ func main() {
|
|||||||
card.TypeName,
|
card.TypeName,
|
||||||
card.SphereName,
|
card.SphereName,
|
||||||
card.Traits,
|
card.Traits,
|
||||||
extractKeywords(card.Text),
|
findKeywords(card.Text),
|
||||||
card.Cost,
|
card.Cost,
|
||||||
card.EngagementCost,
|
card.EngagementCost,
|
||||||
strconv.Itoa(card.Threat),
|
strconv.Itoa(card.Threat),
|
||||||
@ -90,8 +104,8 @@ func main() {
|
|||||||
strconv.Itoa(card.Attack),
|
strconv.Itoa(card.Attack),
|
||||||
strconv.Itoa(card.Defense),
|
strconv.Itoa(card.Defense),
|
||||||
strconv.Itoa(card.Health),
|
strconv.Itoa(card.Health),
|
||||||
"", // Quest Points
|
card.QuestPoints,
|
||||||
"", // Victory Points
|
strconv.Itoa(card.VictoryPoints),
|
||||||
"", // Special Icon
|
"", // Special Icon
|
||||||
transformText(card.Name, card.Text),
|
transformText(card.Name, card.Text),
|
||||||
card.Flavor,
|
card.Flavor,
|
||||||
@ -105,12 +119,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func transformText(name, text string) string {
|
func transformText(name, text string) string {
|
||||||
return strip.StripTags(
|
if opts.RawConversion {
|
||||||
strings.ReplaceAll(text, name, "[name]"), // insert name tag
|
return text
|
||||||
)
|
}
|
||||||
|
|
||||||
|
out := strings.ReplaceAll(text, name, "[name]") // insert name tag
|
||||||
|
out = strip.StripTags(out)
|
||||||
|
out = keywordPattern.ReplaceAllLiteralString(out, "")
|
||||||
|
return strings.TrimSpace(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractKeywords(text string) string {
|
var keywordPattern = regexp.MustCompile(`((?:(?:[A-Z][a-z]+(\.|\s[0-9]+\.)\s*)+))`)
|
||||||
pattern := regexp.MustCompile(`((?:(?:[A-Z][a-z]+(\.|\s[0-9]+\.)\s)+))`)
|
|
||||||
return strings.TrimSpace(pattern.FindString(text))
|
func findKeywords(text string) string {
|
||||||
|
return strings.TrimSpace(keywordPattern.FindString(text))
|
||||||
}
|
}
|
||||||
|
@ -9,29 +9,19 @@ type HallOfBeornCard struct {
|
|||||||
SphereCode string `json:"sphere_code,omitempty"`
|
SphereCode string `json:"sphere_code,omitempty"`
|
||||||
SphereName string `json:"sphere_name,omitempty"`
|
SphereName string `json:"sphere_name,omitempty"`
|
||||||
Position int `json:"position,omitempty"`
|
Position int `json:"position,omitempty"`
|
||||||
Code string `json:"code,omitempty"`
|
|
||||||
Cost string `json:"cost,omitempty"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
Traits string `json:"traits,omitempty"`
|
|
||||||
Text string `json:"text,omitempty"`
|
|
||||||
Flavor string `json:"flavor,omitempty"`
|
|
||||||
IsUnique bool `json:"is_unique,omitempty"`
|
|
||||||
Threat int `json:"threat,omitempty"`
|
Threat int `json:"threat,omitempty"`
|
||||||
Willpower int `json:"willpower,omitempty"`
|
Willpower int `json:"willpower,omitempty"`
|
||||||
Attack int `json:"attack,omitempty"`
|
Attack int `json:"attack,omitempty"`
|
||||||
Defense int `json:"defense,omitempty"`
|
Defense int `json:"defense,omitempty"`
|
||||||
Health int `json:"health,omitempty"`
|
Health int `json:"health,omitempty"`
|
||||||
Quantity int `json:"quantity,omitempty"`
|
|
||||||
DeckLimit int `json:"deck_limit,omitempty"`
|
|
||||||
Illustrator string `json:"illustrator,omitempty"`
|
|
||||||
Octgnid string `json:"octgnid,omitempty"`
|
Octgnid string `json:"octgnid,omitempty"`
|
||||||
HasErrata bool `json:"has_errata,omitempty"`
|
HasErrata bool `json:"has_errata,omitempty"`
|
||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
|
QuestPoints string `json:"quest,omitempty"`
|
||||||
|
VictoryPoints int `json:"victory,omitempty"`
|
||||||
Imagesrc string `json:"imagesrc,omitempty"`
|
Imagesrc string `json:"imagesrc,omitempty"`
|
||||||
|
|
||||||
EncounterSet string `json:"encounter_set,omitempty"`
|
EncounterSet string `json:"encounter_set,omitempty"`
|
||||||
EngagementCost string `json:"engagement_cost,omitempty"`
|
EngagementCost string `json:"engagement_cost,omitempty"`
|
||||||
ThreatStrength int `json:"threat_strength,omitempty"`
|
ThreatStrength int `json:"threat_strength,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NormalizedCard struct{}
|
|
||||||
|
7
deps.bzl
7
deps.bzl
@ -37,6 +37,13 @@ def go_dependencies():
|
|||||||
sum = "h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=",
|
sum = "h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=",
|
||||||
version = "v0.0.1",
|
version = "v0.0.1",
|
||||||
)
|
)
|
||||||
|
go_repository(
|
||||||
|
name = "com_github_jessevdk_go_flags",
|
||||||
|
build_file_proto_mode = "disable_global",
|
||||||
|
importpath = "github.com/jessevdk/go-flags",
|
||||||
|
sum = "h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=",
|
||||||
|
version = "v1.5.0",
|
||||||
|
)
|
||||||
|
|
||||||
go_repository(
|
go_repository(
|
||||||
name = "com_github_mattn_go_sqlite3",
|
name = "com_github_mattn_go_sqlite3",
|
||||||
|
2
go.mod
2
go.mod
@ -7,5 +7,7 @@ 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/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||||
|
github.com/jessevdk/go-flags v1.5.0 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
|
||||||
)
|
)
|
||||||
|
5
go.sum
5
go.sum
@ -4,5 +4,10 @@ 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 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||||
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
||||||
|
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
||||||
|
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||||
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=
|
||||||
|
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
|
||||||
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
Reference in New Issue
Block a user