commit 339ff200effd7790f7a8f7fac98b887c047a3cbc Author: Felipe Martin Date: Fri Aug 12 13:33:32 2022 +0200 wip diff --git a/const.go b/const.go new file mode 100644 index 0000000..abaf225 --- /dev/null +++ b/const.go @@ -0,0 +1,7 @@ +package main + +const ( + sourcesURL = "https://onepiece-cardgame.dev/sources.json" + metaURL = "https://onepiece-cardgame.dev/meta.json" + cardsURL = "https://onepiece-cardgame.dev/cards.json" +) diff --git a/download.go b/download.go new file mode 100644 index 0000000..d927dc5 --- /dev/null +++ b/download.go @@ -0,0 +1,25 @@ +package main + +import ( + "io" + "log" + "net/http" +) + +func downloadURL(u string) ([]byte, error) { + log.Printf("Downloading %s\n", u) + + response, err := http.Get(u) + if err != nil { + return nil, err + } + + defer response.Body.Close() + + body, err := io.ReadAll(response.Body) + if err != nil { + return nil, err + } + + return body, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..833dfcc --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module code.fmartingr.dev/fmartingr/onepiece-tcg-notion-importer + +go 1.18 + +require github.com/dstotijn/go-notion v0.6.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4f9c641 --- /dev/null +++ b/go.sum @@ -0,0 +1,5 @@ +github.com/dstotijn/go-notion v0.6.1 h1:gmwU/JCdLC5szMasfysDOm8UG6/3P0bTUe0+CeW2fmI= +github.com/dstotijn/go-notion v0.6.1/go.mod h1:oxd+T9Wxduj5ZN7MRiHWtyGhGZLUFsUpZHMLS4uI1Qc= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go new file mode 100644 index 0000000..67ad878 --- /dev/null +++ b/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "context" + "encoding/json" + "log" + + "github.com/dstotijn/go-notion" +) + +const ( + collectionsDatabaseID = "32fc86afa91e4718b17cb79ab8794265" +) + +func main() { + content, err := downloadURL(sourcesURL) + if err != nil { + panic(err) + } + + log.Println(string(content)) + + var sources []source + if err := json.Unmarshal(content, &sources); err != nil { + panic(err) + } + + ctx := context.Background() + dbSources := make(map[string]notion.Page) + + client := notion.NewClient("secret_135hSjxx1xcFWcrjcS1eejjp120T86V8sIGzVeW21X4") + + result, err := client.QueryDatabase(ctx, collectionsDatabaseID, ¬ion.DatabaseQuery{}) + if err != nil { + panic(err) + } + + for _, s := range result.Results { + dbSources[s.Properties.(notion.DatabasePageProperties)["SourceID"].Value().(string)] = s + } + + // for _, s := range sources { + + // } +} diff --git a/meta.json b/meta.json new file mode 100644 index 0000000..c22168a --- /dev/null +++ b/meta.json @@ -0,0 +1,282 @@ +{ + "a": [ + { + "atk_id": "0", + "name": "NA" + }, + { + "atk_id": "1", + "name": "Slash" + }, + { + "atk_id": "2", + "name": "Strike" + }, + { + "atk_id": "3", + "name": "Ranged" + }, + { + "atk_id": "4", + "name": "Wisdom" + }, + { + "atk_id": "5", + "name": "Special" + } + ], + "c": [ + { + "color_id": "1", + "name": "Red" + }, + { + "color_id": "4", + "name": "Purple" + }, + { + "color_id": "5", + "name": "DON" + }, + { + "color_id": "6", + "name": "Blue" + }, + { + "color_id": "7", + "name": "Green" + }, + { + "color_id": "8", + "name": "Blue/Green" + }, + { + "color_id": "9", + "name": "Red/Blue" + }, + { + "color_id": "10", + "name": "Red/Green" + }, + { + "color_id": "11", + "name": "Blue/Purple" + } + ], + "s": [ + { + "src_id": "0", + "name": "TBD", + "intl": "0", + "release_date": null, + "imageURL": "", + "t": "0", + "filter": "" + }, + { + "src_id": "1", + "name": "Romance Dawn [OP-01]", + "intl": "0", + "release_date": null, + "imageURL": "https://onepiece-cardgame.dev/images/static/OP01.jpg", + "t": "2", + "filter": "[OP-01]" + }, + { + "src_id": "2", + "name": "Straw Hat Crew [ST-01]", + "intl": "0", + "release_date": "2022-12-01", + "imageURL": "https://onepiece-cardgame.dev/images/static/ST01.jpg", + "t": "1", + "filter": "[ST-01]" + }, + { + "src_id": "3", + "name": "Worst Generation [ST-02]", + "intl": "0", + "release_date": null, + "imageURL": "https://onepiece-cardgame.dev/images/static/ST02.jpg", + "t": "1", + "filter": "[ST-02]" + }, + { + "src_id": "4", + "name": "The Seven Warlords of the Sea [ST-03]", + "intl": "0", + "release_date": null, + "imageURL": "https://onepiece-cardgame.dev/images/static/ST03.jpg", + "t": "1", + "filter": "[ST-03]" + }, + { + "src_id": "5", + "name": "Animal Kingdom Pirates [ST-04]", + "intl": "0", + "release_date": null, + "imageURL": "https://onepiece-cardgame.dev/images/static/ST04.jpg", + "t": "1", + "filter": "[ST-04]" + }, + { + "src_id": "6", + "name": "One Piece Film Edition [ST-05]", + "intl": "0", + "release_date": null, + "imageURL": "https://onepiece-cardgame.dev/images/static/ST05a.jpg", + "t": "1", + "filter": "[ST-05]" + }, + { + "src_id": "7", + "name": "Marine [OP-02]", + "intl": "0", + "release_date": null, + "imageURL": "https://onepiece-cardgame.dev/cardback2.jpg", + "t": "2", + "filter": "[OP-02]" + }, + { + "src_id": "8", + "name": "Promo [P]", + "intl": "0", + "release_date": null, + "imageURL": "https://onepiece-cardgame.dev/cardback2.jpg", + "t": "3", + "filter": "[P]" + }, + { + "src_id": "9", + "name": "Misc [MISC]", + "intl": "0", + "release_date": null, + "imageURL": "", + "t": "3", + "filter": "[MISC]" + } + ], + "t": [ + { + "type_id": "1", + "name": "leader" + }, + { + "type_id": "2", + "name": "character" + }, + { + "type_id": "3", + "name": "event" + }, + { + "type_id": "4", + "name": "stage" + }, + { + "type_id": "5", + "name": "don" + } + ], + "ct": [ + { + "type_id": "1", + "name": "leader" + }, + { + "type_id": "2", + "name": "character" + }, + { + "type_id": "3", + "name": "event" + }, + { + "type_id": "4", + "name": "stage" + }, + { + "type_id": "5", + "name": "don" + } + ], + "r": [ + { + "rarity_id": "0", + "name": "TBD" + }, + { + "rarity_id": "1", + "name": "Leader" + }, + { + "rarity_id": "2", + "name": "Common" + }, + { + "rarity_id": "3", + "name": "Uncommon" + }, + { + "rarity_id": "4", + "name": "Rare" + }, + { + "rarity_id": "5", + "name": "Super Rare" + }, + { + "rarity_id": "6", + "name": "Secret Rare" + }, + { + "rarity_id": "7", + "name": "Promo" + } + ], + "key": [ + { + "id": "1", + "name": "Rush" + }, + { + "id": "2", + "name": "[On Play]" + }, + { + "id": "3", + "name": "Double Attack" + }, + { + "id": "4", + "name": "Blocker" + }, + { + "id": "5", + "name": "[When Attacking]" + }, + { + "id": "6", + "name": "Banish" + }, + { + "id": "7", + "name": "[DON!!" + }, + { + "id": "8", + "name": "[On K.O.]" + }, + { + "id": "9", + "name": "[On Block]" + }, + { + "id": "10", + "name": "[Activate" + }, + { + "id": "11", + "name": "[Double Attack]" + } + ] +} diff --git a/sources.json b/sources.json new file mode 100644 index 0000000..11e81a9 --- /dev/null +++ b/sources.json @@ -0,0 +1,92 @@ +[ + { + "src_id": "0", + "name": "TBD", + "intl": "0", + "release_date": null, + "imageURL": "", + "t": "0", + "filter": "" + }, + { + "src_id": "1", + "name": "Romance Dawn [OP-01]", + "intl": "0", + "release_date": null, + "imageURL": "https:\/\/onepiece-cardgame.dev\/images\/static\/OP01.jpg", + "t": "2", + "filter": "[OP-01]" + }, + { + "src_id": "2", + "name": "Straw Hat Crew [ST-01]", + "intl": "0", + "release_date": "2022-12-01", + "imageURL": "https:\/\/onepiece-cardgame.dev\/images\/static\/ST01.jpg", + "t": "1", + "filter": "[ST-01]" + }, + { + "src_id": "3", + "name": "Worst Generation [ST-02]", + "intl": "0", + "release_date": null, + "imageURL": "https:\/\/onepiece-cardgame.dev\/images\/static\/ST02.jpg", + "t": "1", + "filter": "[ST-02]" + }, + { + "src_id": "4", + "name": "The Seven Warlords of the Sea [ST-03]", + "intl": "0", + "release_date": null, + "imageURL": "https:\/\/onepiece-cardgame.dev\/images\/static\/ST03.jpg", + "t": "1", + "filter": "[ST-03]" + }, + { + "src_id": "5", + "name": "Animal Kingdom Pirates [ST-04]", + "intl": "0", + "release_date": null, + "imageURL": "https:\/\/onepiece-cardgame.dev\/images\/static\/ST04.jpg", + "t": "1", + "filter": "[ST-04]" + }, + { + "src_id": "6", + "name": "One Piece Film Edition [ST-05]", + "intl": "0", + "release_date": null, + "imageURL": "https:\/\/onepiece-cardgame.dev\/images\/static\/ST05a.jpg", + "t": "1", + "filter": "[ST-05]" + }, + { + "src_id": "7", + "name": "Marine [OP-02]", + "intl": "0", + "release_date": null, + "imageURL": "https:\/\/onepiece-cardgame.dev\/cardback2.jpg", + "t": "2", + "filter": "[OP-02]" + }, + { + "src_id": "8", + "name": "Promo [P]", + "intl": "0", + "release_date": null, + "imageURL": "https:\/\/onepiece-cardgame.dev\/cardback2.jpg", + "t": "3", + "filter": "[P]" + }, + { + "src_id": "9", + "name": "Misc [MISC]", + "intl": "0", + "release_date": null, + "imageURL": "", + "t": "3", + "filter": "[MISC]" + } +] diff --git a/types.go b/types.go new file mode 100644 index 0000000..21c7a20 --- /dev/null +++ b/types.go @@ -0,0 +1,77 @@ +package main + +import ( + "encoding/json" + "time" +) + +type isoDate struct { + time.Time +} + +func (d *isoDate) UnmarshalJSON(b []byte) error { + var s string + if err := json.Unmarshal(b, &s); err != nil { + return err + } + t, _ := time.Parse("2006-01-02", s) + d.Time = t + return nil +} +func (d isoDate) MarshalJSON() ([]byte, error) { + return json.Marshal(d.Format("2006-01-02")) +} + +// {"src_id":"0","name":"TBD","intl":"0","release_date":null,"imageURL":"","t":"0","filter":""} +type source struct { + SourceID string `json:"src_id"` + Name string `json:"name"` + International string `json:"intl"` + ReleaseDate isoDate `json:"release_date"` + ImageURL string `json:"image_url"` + T string `json:"t"` + Filter string `json:"filter"` +} + +/* { + "gid": "47", + "cid": "OP01-047", + "n": "Trafalgar Law", + "t": "2", + "col": "7", + "cs": "5", + "tr": "Supernovas\/ Heart Pirates", + "a": "1", + "p": "6000", + "cp": null, + "l": null, + "r": "5", + "ar": null, + "iu": "https:\/\/onepiece-cardgame.dev\/images\/cards\/OP01-047_616aca_jp.jpg", + "e": "\r\n[On Play] You may return one of your Characters to your hand: Play 1 Cost 3 or lower Character Card from your hand.", + "al": null, + "intl": "0", + "srcN": "Romance Dawn [OP-01]", + "srcD": null +} */ +type card struct { + GlobalID string `json:"gid"` + CardID string `json:"cid"` + Name string `json:"n"` + Type string `json:"t"` + Color string `json:"col"` + Source string `json:"cs"` + Tr string `json:"tr"` + AttackType string `json:"a"` + P string `json:"p"` + Cp string `json:"cp"` + L interface{} `json:"l"` + Rarity string `json:"r"` + Ar string `json:"ar"` + ImageURL string `json:"iu"` + E string `json:"e"` + Al interface{} `json:"al"` + International string `json:"intl"` + SourceName string `json:"srcN"` + SrcD interface{} `json:"srcD"` +}