Compare commits
25 Commits
main
..
ec97dae46b
| Author | SHA1 | Date | |
|---|---|---|---|
| ec97dae46b | |||
| 28fae2c39d | |||
| d0dc725d64 | |||
| 74b67313e7 | |||
| 574a07495f | |||
| 8efe9263b1 | |||
| a8b370c7b9 | |||
| 6f40b3a405 | |||
| 328aa0b8f5 | |||
| d37b5ce6c1 | |||
| aecf949a2a | |||
| decd76f19d | |||
| dad6f57d6d | |||
| f189432d24 | |||
| 53207a1865 | |||
| dfd84d2172 | |||
| a2e269c3f3 | |||
| a40db899c9 | |||
| 78f4f71743 | |||
| 2c27d0f51d | |||
| d53f356dcd | |||
| 18b35c7ea9 | |||
| 96b5352755 | |||
| e3ebf6d71e | |||
| 1f5135d9bd |
@@ -18,8 +18,3 @@ gazelle(
|
|||||||
],
|
],
|
||||||
command = "update-repos",
|
command = "update-repos",
|
||||||
)
|
)
|
||||||
|
|
||||||
alias(
|
|
||||||
name = "beornextract",
|
|
||||||
actual = "//cmd/beornextract:beornextract",
|
|
||||||
)
|
|
||||||
|
|||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
/private/var/tmp/_bazel_christian/3262850bcac806b0124f7f44b81dceb1/execroot/__main__
|
||||||
+7
-16
@@ -1,26 +1,17 @@
|
|||||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
package(
|
package(
|
||||||
default_visibility = ["//visibility:public"],
|
default_visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
alias(
|
||||||
|
name = "beornextract",
|
||||||
|
actual = "//beornextract/",
|
||||||
|
)
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "beornextract_lib",
|
name = "beornextract_lib",
|
||||||
srcs = ["main.go"],
|
srcs = ["main.go"],
|
||||||
data = [
|
|
||||||
"//cmd/beornextract/data:Bot.Cards.json",
|
|
||||||
"//cmd/beornextract/data:Export.Cards.json",
|
|
||||||
],
|
|
||||||
importpath = "github.com/squk/lotr/cmd/beornextract",
|
importpath = "github.com/squk/lotr/cmd/beornextract",
|
||||||
deps = [
|
deps = ["@com_github_davecgh_go_spew//spew"],
|
||||||
"//cmd/beornextract/types",
|
|
||||||
"@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",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
go_binary(
|
|
||||||
name = "beornextract",
|
|
||||||
embed = [":beornextract_lib"],
|
|
||||||
)
|
)
|
||||||
|
|||||||
+16
-121
@@ -1,136 +1,31 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"github.com/squk/lotr/extract/types"
|
||||||
"regexp"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
|
||||||
strip "github.com/grokify/html-strip-tags-go"
|
|
||||||
"github.com/jessevdk/go-flags"
|
|
||||||
"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(".")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
err = filepath.Walk(f,
|
|
||||||
func(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println(path, info.Size())
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open our jsonFile
|
// Open our jsonFile
|
||||||
// jsonFile, err := os.Open("cmd/beornextract/data/Bot.Cards.json")
|
jsonFile, err := os.Open("./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)
|
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)
|
||||||
cards := []types.HallOfBeornCard{}
|
c := []types.HallOfBeornCard{}
|
||||||
json.Unmarshal(byteValue, &cards)
|
json.Unmarshal(byteValue, &c)
|
||||||
|
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,
|
|
||||||
findKeywords(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),
|
|
||||||
card.QuestPoints,
|
|
||||||
strconv.Itoa(card.VictoryPoints),
|
|
||||||
"", // Special Icon
|
|
||||||
transformText(card.Name, card.Text),
|
|
||||||
card.Flavor,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the writer
|
|
||||||
w.Flush()
|
|
||||||
// spew.Dump(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func transformText(name, text string) string {
|
|
||||||
if opts.RawConversion {
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
|
|
||||||
out := strings.ReplaceAll(text, name, "[name]") // insert name tag
|
|
||||||
out = strip.StripTags(out)
|
|
||||||
out = keywordPattern.ReplaceAllLiteralString(out, "")
|
|
||||||
return strings.TrimSpace(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
var keywordPattern = regexp.MustCompile(`((?:(?:[A-Z][a-z]+(\.|\s[0-9]+\.)\s*)+))`)
|
|
||||||
|
|
||||||
func findKeywords(text string) string {
|
|
||||||
return strings.TrimSpace(keywordPattern.FindString(text))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,33 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type HallOfBeornCard struct {
|
type HallOfBeornCard struct {
|
||||||
PackCode string `json:"pack_code,omitempty"`
|
PackCode string `json:"pack_code"`
|
||||||
PackName string `json:"pack_name,omitempty"`
|
PackName string `json:"pack_name"`
|
||||||
IsOfficial bool `json:"is_official,omitempty"`
|
IsOfficial bool `json:"is_official"`
|
||||||
TypeCode string `json:"type_code,omitempty"`
|
TypeCode string `json:"type_code"`
|
||||||
TypeName string `json:"type_name,omitempty"`
|
TypeName string `json:"type_name"`
|
||||||
SphereCode string `json:"sphere_code,omitempty"`
|
SphereCode string `json:"sphere_code"`
|
||||||
SphereName string `json:"sphere_name,omitempty"`
|
SphereName string `json:"sphere_name"`
|
||||||
Position int `json:"position,omitempty"`
|
Position int `json:"position"`
|
||||||
Threat int `json:"threat,omitempty"`
|
Code string `json:"code"`
|
||||||
Willpower int `json:"willpower,omitempty"`
|
Name string `json:"name"`
|
||||||
Attack int `json:"attack,omitempty"`
|
Traits string `json:"traits"`
|
||||||
Defense int `json:"defense,omitempty"`
|
Text string `json:"text"`
|
||||||
Health int `json:"health,omitempty"`
|
Flavor string `json:"flavor"`
|
||||||
Octgnid string `json:"octgnid,omitempty"`
|
IsUnique bool `json:"is_unique"`
|
||||||
HasErrata bool `json:"has_errata,omitempty"`
|
Threat int `json:"threat"`
|
||||||
URL string `json:"url,omitempty"`
|
Willpower int `json:"willpower"`
|
||||||
QuestPoints string `json:"quest,omitempty"`
|
Attack int `json:"attack"`
|
||||||
VictoryPoints int `json:"victory,omitempty"`
|
Defense int `json:"defense"`
|
||||||
Imagesrc string `json:"imagesrc,omitempty"`
|
Health int `json:"health"`
|
||||||
|
Quantity int `json:"quantity"`
|
||||||
EncounterSet string `json:"encounter_set,omitempty"`
|
DeckLimit int `json:"deck_limit"`
|
||||||
EngagementCost string `json:"engagement_cost,omitempty"`
|
Illustrator string `json:"illustrator"`
|
||||||
ThreatStrength int `json:"threat_strength,omitempty"`
|
Octgnid string `json:"octgnid"`
|
||||||
|
HasErrata bool `json:"has_errata"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Imagesrc string `json:"imagesrc"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NormalizedCard struct {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
load("@bazel_gazelle//:deps.bzl", "go_repository")
|
load("@bazel_gazelle//:deps.bzl", "go_repository")
|
||||||
|
|
||||||
def go_dependencies():
|
def go_dependencies():
|
||||||
go_repository(
|
|
||||||
name = "com_github_bazelbuild_rules_go",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "github.com/bazelbuild/rules_go",
|
|
||||||
sum = "h1:JzlRxsFNhlX+g4drDRPhIaU5H5LnI978wdMJ0vK4I+k=",
|
|
||||||
version = "v0.41.0",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_repository(
|
go_repository(
|
||||||
name = "com_github_davecgh_go_spew",
|
name = "com_github_davecgh_go_spew",
|
||||||
build_file_proto_mode = "disable_global",
|
build_file_proto_mode = "disable_global",
|
||||||
@@ -16,34 +8,6 @@ def go_dependencies():
|
|||||||
sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
|
sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
|
||||||
version = "v1.1.1",
|
version = "v1.1.1",
|
||||||
)
|
)
|
||||||
go_repository(
|
|
||||||
name = "com_github_golang_mock",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "github.com/golang/mock",
|
|
||||||
sum = "h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=",
|
|
||||||
version = "v1.6.0",
|
|
||||||
)
|
|
||||||
go_repository(
|
|
||||||
name = "com_github_golang_protobuf",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "github.com/golang/protobuf",
|
|
||||||
sum = "h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=",
|
|
||||||
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(
|
|
||||||
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",
|
||||||
@@ -52,45 +16,3 @@ def go_dependencies():
|
|||||||
sum = "h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=",
|
sum = "h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=",
|
||||||
version = "v1.14.17",
|
version = "v1.14.17",
|
||||||
)
|
)
|
||||||
go_repository(
|
|
||||||
name = "org_golang_google_genproto",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "google.golang.org/genproto",
|
|
||||||
sum = "h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=",
|
|
||||||
version = "v0.0.0-20200526211855-cb27e3aa2013",
|
|
||||||
)
|
|
||||||
go_repository(
|
|
||||||
name = "org_golang_google_grpc",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "google.golang.org/grpc",
|
|
||||||
sum = "h1:fPVVDxY9w++VjTZsYvXWqEf9Rqar/e+9zYfxKK+W+YU=",
|
|
||||||
version = "v1.50.0",
|
|
||||||
)
|
|
||||||
go_repository(
|
|
||||||
name = "org_golang_google_protobuf",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "google.golang.org/protobuf",
|
|
||||||
sum = "h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=",
|
|
||||||
version = "v1.28.0",
|
|
||||||
)
|
|
||||||
go_repository(
|
|
||||||
name = "org_golang_x_net",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "golang.org/x/net",
|
|
||||||
sum = "h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=",
|
|
||||||
version = "v0.0.0-20210405180319-a5a99cb37ef4",
|
|
||||||
)
|
|
||||||
go_repository(
|
|
||||||
name = "org_golang_x_sys",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "golang.org/x/sys",
|
|
||||||
sum = "h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=",
|
|
||||||
version = "v0.0.0-20210510120138-977fb7262007",
|
|
||||||
)
|
|
||||||
go_repository(
|
|
||||||
name = "org_golang_x_text",
|
|
||||||
build_file_proto_mode = "disable_global",
|
|
||||||
importpath = "golang.org/x/text",
|
|
||||||
sum = "h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=",
|
|
||||||
version = "v0.3.3",
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -4,10 +4,4 @@ go 1.19
|
|||||||
|
|
||||||
require github.com/davecgh/go-spew v1.1.1
|
require github.com/davecgh/go-spew v1.1.1
|
||||||
|
|
||||||
require (
|
require github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
||||||
github.com/bazelbuild/rules_go v0.41.0 // 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
|
|
||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,13 +1,4 @@
|
|||||||
github.com/bazelbuild/rules_go v0.41.0 h1:JzlRxsFNhlX+g4drDRPhIaU5H5LnI978wdMJ0vK4I+k=
|
|
||||||
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/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