stuff
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
alias(
|
||||
name = "beornextract",
|
||||
actual = "//beornextract/",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "beornextract_lib",
|
||||
srcs = ["main.go"],
|
||||
importpath = "github.com/squk/lotr/beornextract",
|
||||
deps = ["@com_github_davecgh_go_spew//spew"],
|
||||
)
|
||||
@@ -0,0 +1,2 @@
|
||||
exports_files(glob(["*.json"]))
|
||||
# exports_files(["Export.Cards.json"])
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,31 @@
|
||||
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("./data/Bot.Cards.json")
|
||||
// if we os.Open returns an error then handle it
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
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.HallOfBeornCard{}
|
||||
json.Unmarshal(byteValue, &c)
|
||||
spew.Dump(c)
|
||||
}
|
||||
@@ -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/beornextract/types",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
package types
|
||||
|
||||
type HallOfBeornCard 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"`
|
||||
}
|
||||
|
||||
type NormalizedCard struct {
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
spew.Dump(os.Getwd())
|
||||
|
||||
os.Remove("./foo.db")
|
||||
|
||||
db, err := sql.Open("sqlite3", "./foo.db")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
sqlStmt := `
|
||||
create table foo (id integer not null primary key, name text);
|
||||
delete from foo;
|
||||
`
|
||||
_, err = db.Exec(sqlStmt)
|
||||
if err != nil {
|
||||
log.Printf("%q: %s\n", err, sqlStmt)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
stmt, err := tx.Prepare("insert into foo(id, name) values(?, ?)")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err = stmt.Exec(i, fmt.Sprintf("こんにちは世界%03d", i))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
rows, err := db.Query("select id, name from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var name string
|
||||
err = rows.Scan(&id, &name)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(id, name)
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
stmt, err = db.Prepare("select name from foo where id = ?")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
var name string
|
||||
err = stmt.QueryRow("3").Scan(&name)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(name)
|
||||
|
||||
_, err = db.Exec("delete from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = db.Exec("insert into foo(id, name) values(1, 'foo'), (2, 'bar'), (3, 'baz')")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
rows, err = db.Query("select id, name from foo")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var name string
|
||||
err = rows.Scan(&id, &name)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(id, name)
|
||||
}
|
||||
err = rows.Err()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user