mtgdb

package module
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2023 License: LGPL-3.0 Imports: 21 Imported by: 0

README

MTGDB

Go

MTGDB is a tool written in GO to create and populate a database with all Magic The Gathering cards available from Scryfall. MTGDB also download the image of each card.

Install

go install github.com/pioz/mtgdb/cmd/mtgdb@latest
mtgdb -h
From sources
git clone github.com/pioz/mtgdb
cd mtgdb
# go test
go build -o mtgdb ./cmd/mtgdb/main.go
./mtgdb -h

Usage

Before using MTGDB you have to set 2 environment variables (also .env file works):

  • DB_CONNECTION -> database connection string (example user@tcp(127.0.0.1:3306)/mtgdb?charset=utf8mb4&parseTime=True)
  • DATA_PATH -> path where download assets like card images (example ./data)

The first time you run MTGDB, it will migrate also the database creating the tables.

mtgdb -h
Usage of mtgdb:
  -download-concurrency int
    	Set max download concurrency
  -en
    	Download card images only in EN language (default true)
  -f	Force re-download of card images
  -fsha1
    	Force re-download of card images, but only if the sha1sum is changed
  -ftime
    	Force re-download of card images, but only if the modified date is older
  -h	Print this help
  -only string
    	Import some sets (es: -only eld,war)
  -p	Display progress bar
  -skip-assets
    	Skip download of set and card images
  -u	Update Scryfall database

Questions or problems?

If you have any issues please add an issue on GitHub or fork the project and send a pull request.

Copyright (c) 2020 Enrico Pilotto (@pioz). See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB)

func BulkInsert

func BulkInsert(db *gorm.DB, cards []Card) error

func CardImagePath

func CardImagePath(imagesDir, setCode, collectorNumber, locale string, backImage bool) string

func CardImagesDir

func CardImagesDir(imagesDir string) string

func FillMissingTranslations added in v0.1.1

func FillMissingTranslations(db *gorm.DB) error

func SetImagePath

func SetImagePath(imagesDir, setCode string) string

func SetImagesDir

func SetImagesDir(imagesDir string) string

Types

type Card

type Card struct {
	ID uint `gorm:"primary_key"`

	EnName  string `gorm:"size:255;not null;index;index:idxft_cards_en_name,class:FULLTEXT"`
	EsName  string `gorm:"size:255;not null"`
	FrName  string `gorm:"size:255;not null"`
	DeName  string `gorm:"size:255;not null"`
	ItName  string `gorm:"size:255;not null"`
	PtName  string `gorm:"size:255;not null"`
	JaName  string `gorm:"size:255;not null"`
	KoName  string `gorm:"size:255;not null"`
	RuName  string `gorm:"size:255;not null"`
	ZhsName string `gorm:"size:255;not null"`
	ZhtName string `gorm:"size:255;not null"`

	SetCode string `gorm:"size:6;not null;uniqueIndex:idx_cards_set_code_collector_number"`
	Set     *Set   `gorm:"foreignkey:SetCode;references:Code;constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"`

	CollectorNumber string `gorm:"size:255;not null;uniqueIndex:idx_cards_set_code_collector_number"`
	Foil            bool   `gorm:"not null"`
	NonFoil         bool   `gorm:"not null"`
	HasBackSide     bool   `gorm:"not null"`
	ReleasedAt      *time.Time
	FrontImageUrl   string `gorm:"size:255;not null"`
	BackImageUrl    string `gorm:"size:255"`

	Artist             string `gorm:"size:255"`
	ArtistBack         string `gorm:"size:255"`
	Booster            bool
	BorderColor        string `gorm:"size:255"`
	CMC                float32
	CMCBack            float32
	ColorIdentity      SliceString `gorm:"type:json"`
	ColorIndicator     SliceString `gorm:"type:json"`
	ColorIndicatorBack SliceString `gorm:"type:json"`
	Colors             SliceString `gorm:"type:json"`
	ColorsBack         SliceString `gorm:"type:json"`
	ContentWarning     bool
	Digital            bool
	Finishes           SliceString `gorm:"type:json"`
	FlavorName         string      `gorm:"size:255"`
	FlavorText         string
	FlavorTextBack     string
	Frame              string      `gorm:"size:255"`
	FrameEffects       SliceString `gorm:"type:json"`
	FullArt            bool
	Games              SliceString `gorm:"type:json"`
	HandModifier       string      `gorm:"size:255"`
	Keywords           SliceString `gorm:"type:json"`
	Layout             string      `gorm:"size:255"`
	LayoutBack         string      `gorm:"size:255"`
	Legalities         MapString   `gorm:"type:json"`
	LifeModifier       string      `gorm:"size:255"`
	Loyalty            string      `gorm:"size:255"`
	LoyaltyBack        string      `gorm:"size:255"`
	ManaCost           string      `gorm:"size:255"`
	ManaCostBack       string      `gorm:"size:255"`
	OracleText         string
	OracleTextBack     string
	Oversized          bool
	Power              string      `gorm:"size:255"`
	PowerBack          string      `gorm:"size:255"`
	ProducedMana       SliceString `gorm:"type:json"`
	Promo              bool
	Rarity             string `gorm:"size:255"`
	Reprint            bool
	Reserved           bool
	SecurityStamp      string `gorm:"size:255"`
	StorySpotlight     bool
	Textless           bool
	Toughness          string `gorm:"size:255"`
	ToughnessBack      string `gorm:"size:255"`
	TypeLine           string `gorm:"size:255"`
	TypeLineBack       string `gorm:"size:255"`
	Variation          bool
	Watermark          string `gorm:"size:255"`
	WatermarkBack      string `gorm:"size:255"`

	ScryfallID   string `gorm:"size:255;not null"`
	OracleID     string `gorm:"size:255"`
	MtgoID       uint64
	ArenaID      uint64
	TcgplayerID  uint64
	CardmarketID uint64

	Rulings Rulings `gorm:"type:json"`
}

func (*Card) ImagePath

func (card *Card) ImagePath(dataImagesPath, locale string, backImage bool) string

func (*Card) IsValid

func (card *Card) IsValid() bool

func (*Card) SetName

func (card *Card) SetName(name, language string)

type Importer

type Importer struct {
	DataDir                  string
	ImagesDir                string
	OnlyTheseSetCodes        []string
	ForceDownloadData        bool
	DownloadAssets           bool
	DownloadOnlyEnAssets     bool
	ForceDownloadOlderAssets bool
	ForceDownloadDiffSha1    bool
	ForceDownloadAssets      bool
	ImageType                string
	DisplayProgressBar       bool
	// contains filtered or unexported fields
}

func NewImporter

func NewImporter(dataDir string) *Importer

func (*Importer) BuildCardsFromJson

func (importer *Importer) BuildCardsFromJson() ([]Card, uint32)

func (*Importer) DownloadData

func (importer *Importer) DownloadData() error

func (*Importer) SetDownloadConcurrency

func (importer *Importer) SetDownloadConcurrency(n int)

type JsonStreamer

type JsonStreamer struct {
	*json.Decoder
	// contains filtered or unexported fields
}

func NewJsonStreamer

func NewJsonStreamer(filepath string) (*JsonStreamer, error)

func (*JsonStreamer) Get

func (streamer *JsonStreamer) Get(out interface{}) error

func (*JsonStreamer) Next

func (streamer *JsonStreamer) Next() bool

type MapString added in v0.5.0

type MapString map[string]interface{}

func (*MapString) Scan added in v0.5.0

func (j *MapString) Scan(value interface{}) error

func (MapString) Value added in v0.5.0

func (j MapString) Value() (driver.Value, error)

type Ruling added in v0.5.0

type Ruling struct {
	PublishedAt *time.Time `json:"published_at"`
	Comment     string     `json:"comment"`
}

func (*Ruling) Scan added in v0.5.0

func (j *Ruling) Scan(value interface{}) error

func (Ruling) Value added in v0.5.0

func (j Ruling) Value() (driver.Value, error)

type Rulings added in v0.5.0

type Rulings []Ruling

func (*Rulings) Scan added in v0.5.0

func (j *Rulings) Scan(value interface{}) error

func (Rulings) Value added in v0.5.0

func (j Rulings) Value() (driver.Value, error)

type Set

type Set struct {
	ID         uint   `gorm:"primary_key"`
	Name       string `gorm:"size:255;not null"`
	Code       string `gorm:"size:6;not null;uniqueIndex"`
	ParentCode string `gorm:"size:6;not null;index"`
	ReleasedAt *time.Time
	Typology   string `gorm:"size:255;not null"`
	IconName   string `gorm:"size:255;not null"`
}

func (*Set) ImagePath

func (set *Set) ImagePath(dataImagesPath string) string

type SliceString added in v0.5.0

type SliceString []string

func (*SliceString) Scan added in v0.5.0

func (j *SliceString) Scan(value interface{}) error

func (SliceString) Value added in v0.5.0

func (j SliceString) Value() (driver.Value, error)

type Token

type Token interface{}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL