Documentation
¶
Overview ¶
Package fetch retrieves desired information from the [en.]ws-tcg.com websites.
Index ¶
- Constants
- Variables
- func IsbaseRarity(card Card) bool
- type Booster
- type Card
- type CardColor
- type CardType
- type Client
- func (c *Client) Boosters(ctx context.Context, cfg Config) (map[string]Booster, error)
- func (c *Client) Cards(ctx context.Context, cfg Config) ([]Card, error)
- func (c *Client) CardsStream(ctx context.Context, cfg Config, cardCh chan<- Card) error
- func (c *Client) Close()
- func (c *Client) DeckConstruction(ctx context.Context, cfg DeckRulesConfig) ([]TitleDeckGroup, error)
- func (c *Client) DeckRules(ctx context.Context, cfg DeckRulesConfig) (DeckRules, error)
- func (c *Client) ExpansionList(ctx context.Context, cfg Config) (map[int]string, error)
- func (c *Client) Products(ctx context.Context, page string) ([]ProductInfo, error)
- type Config
- type DeckRules
- type DeckRulesConfig
- type ExpansionSourceType
- type FreeFloaterGroup
- type Option
- func WithBurst(burst int) Option
- func WithCache(dir string, ttl time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxRetries(maxRetries int) Option
- func WithNetworkConcurrency(concurrency int) Option
- func WithProxyURL(raw string) Option
- func WithRequestTimeout(timeout time.Duration) Option
- func WithRequestsPerSecond(rps float64) Option
- func WithRespectRobots(enabled bool) Option
- func WithUserAgent(userAgent string) Option
- type ProductInfo
- type RestrictionCard
- type RestrictionGroup
- type RestrictionType
- type Side
- type SiteLanguage
- type TitleDeckGroup
- type Trigger
Constants ¶
const ProductsURL = "https://ws-tcg.com/products/page/"
Variables ¶
var ErrBlocked = errors.New("scraper blocked by remote site")
Functions ¶
func IsbaseRarity ¶
IsbaseRarity check if a card is a C / U / R / RR
Types ¶
type Card ¶
type Card struct {
// CardNumber is the full card number/code used to identify each card.
// It typically consists of the SetID, Side, Release, ReleasePackID, and ID,
// though the format is different in some situations.
CardNumber string `json:"cardNumber"`
// SetID is the alphanumeric string found at the beginning of card numbers,
// before the "/"".
SetID string `json:"setId"`
// SetName is the official name of the set/IP.
// It is currently unset by the scraper and is reserved for when the websites
// expose one or the scraper is updated to find it.
SetName string `json:"setName"`
// ExpansionName is the normalized product/expansion title shown on card pages
// (eg. "Love Live! Vol.2"). This may differ from the product page title.
ExpansionName string `json:"expansionName"`
// ExpansionSlug is the official product slug for normal releases when available.
// Promo cards use a best-effort code from promo metadata, with ReleasePackID as
// a fallback when the listing doesn't expose one.
ExpansionSlug string `json:"expansionSlug"`
// ExpansionProductDisplayName is the product page title for normal releases or
// the specific promo group/distribution name from the promo listing.
ExpansionProductDisplayName string `json:"expansionProductDisplayName"`
// ExpansionProductURL is the product page URL when the card page links to one.
ExpansionProductURL string `json:"expansionProductURL,omitempty"`
// ExpansionSourceType indicates whether the richer expansion metadata came from
// a linked product page or an official promo listing.
ExpansionSourceType ExpansionSourceType `json:"expansionSourceType"`
// Sides contains the card's side ("W" for Weiss, "S" for Schwarz).
// Some cards are dual-sided (eg. Gso/WS02-124SP and Gso/WS02-E124SP).
Sides []Side `json:"sides,omitempty"`
// Release typically consists of the card's side, followed by a number
// (the release pack ID) indicating which consecutive release for the relative
// side the release is.
// For example, "W64" would mean the 64th set of the Weiss side.
// There are certain situations that don't follow the aforementioned format,
// such as with promo cards (eg. BSF2024) or special sets (eg. EN-W03).
Release string `json:"release"`
// ReleasePackID indicates which consecutive release for the relative
// side the release is.
// For example, "W64" would mean the 64th set of the Weiss side.
// For cards with non-standard release codes, a best-effort/most sensible
// ID is chosen (eg. 2021 from BSL2021). This may be empty if there's
// no sensible ID to choose (eg. from TCPR-P01).
ReleasePackID string `json:"releasePackId"`
// ID of the card within the set+release. This is usually the last part
// of the card number (after the -).
ID string `json:"id"`
// Language the card is printed in.
Language string `json:"language"`
// Type can be either "CH" for character, "EV" for event, or "CX" for climax.
Type CardType `json:"type"`
// Name of the card.
Name string `json:"name"`
// Color of the card. Should be either "BLUE", "GREEN", "RED", or "YELLOW".
// ...Except for the two purple cards (むらさきパプリス(PY/S38-125) and むらさきぷよ(PY/S38-120)).
Color CardColor `json:"color"`
// Stock cost to play the card.
Cost *int `json:"cost,omitempty"`
// Level required in order to play the card.
Level *int `json:"level,omitempty"`
// Power indicates the card's battle strength. Only valid for Character cards.
Power *int `json:"power,omitempty"`
// Soul indicates how many soul points the card has. Only valid for Character cards.
Soul *int `json:"soul,omitempty"`
// Text describing the card's abilities.
Text []string `json:"text"`
// Traits indicating the attributes the card has. These are often referenced in card text.
Traits []string `json:"traits,omitempty"`
// Triggers that the card has and are activated during trigger checks.
Triggers []Trigger `json:"triggers,omitempty"`
// ParseFailures captures non-fatal parsing issues where the remaining card data
// still looked trustworthy enough to keep.
ParseFailures []string `json:"parseFailures,omitempty"`
FlavorText string `json:"flavorText,omitempty"`
ImageURL string `json:"imageURL"`
Image image.Image `json:"-"`
Rarity string `json:"rarity"`
}
Card info to export
type Client ¶ added in v0.1.3
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CardsStream ¶ added in v0.1.3
func (*Client) DeckConstruction ¶ added in v0.2.0
func (c *Client) DeckConstruction(ctx context.Context, cfg DeckRulesConfig) ([]TitleDeckGroup, error)
DeckConstruction fetches and parses the official deck-construction rules page for the requested language and returns normalized, side-aware title groups.
func (*Client) DeckRules ¶ added in v0.2.0
DeckRules fetches and parses the official deck-construction rules page for the requested language and returns normalized title groups plus card-level restriction data.
func (*Client) ExpansionList ¶ added in v0.1.3
ExpansionList returns a map of expansion numbers to their titles for the specified language in the Config.
type Config ¶
type Config struct {
// The website's internal code for each expansion. The value is language-specific.
// For example,
// 159 is "BanG Dream! Girls Band Party Premium Booster" in EN
// 159 is "Monogatari Series: Second Season"
ExpansionNumber int
GetAllRarities bool
GetImages bool
GetRecent bool
Language SiteLanguage
PageStart int
Reverse bool
SetCode []string
// The website's internal code for each set. The value is language-specific.
// For example
// 159 is "Tokyo Revengers" in EN
// 159 isn't supported in JP
TitleNumber int
}
type DeckRules ¶ added in v0.2.0
type DeckRules struct {
TitleDeckGroups []TitleDeckGroup `json:"titleDeckGroups"`
FreeFloaters []FreeFloaterGroup `json:"freeFloaters,omitempty"`
RestrictionsByGroup map[string][]RestrictionGroup `json:"restrictionsByGroup,omitempty"`
}
DeckRules contains the parsed deck-rules data for one language, including title groups and card-level restrictions.
type DeckRulesConfig ¶ added in v0.2.0
type DeckRulesConfig struct {
// Language selects which official site to parse.
Language SiteLanguage
}
type ExpansionSourceType ¶ added in v0.2.1
type ExpansionSourceType string
ExpansionSourceType identifies where the enriched expansion metadata came from.
const ( ExpansionSourceTypeProductPage ExpansionSourceType = "product_page" ExpansionSourceTypePromoListing ExpansionSourceType = "promo_listing" )
type FreeFloaterGroup ¶ added in v0.2.0
type FreeFloaterGroup struct {
Label string `json:"label"`
Cards []RestrictionCard `json:"cards"`
Notes []string `json:"notes,omitempty"`
SourceLanguage string `json:"sourceLanguage"`
SourceURL string `json:"sourceURL"`
}
FreeFloaterGroup describes cards that can be used across otherwise separate deck groupings, such as the English "any format" list.
type Option ¶ added in v0.1.3
func WithLogger ¶ added in v0.1.3
func WithMaxRetries ¶ added in v0.1.3
func WithNetworkConcurrency ¶ added in v0.1.3
func WithProxyURL ¶ added in v0.1.3
func WithRequestTimeout ¶ added in v0.1.3
func WithRequestsPerSecond ¶ added in v0.1.3
func WithRespectRobots ¶ added in v0.1.3
func WithUserAgent ¶ added in v0.1.3
type ProductInfo ¶
type ProductInfo struct {
ReleaseDate string
Title string
LicenceCode string
Image string
SetCode string
}
ProductInfo represents the extracted information from the HTML
type RestrictionCard ¶ added in v0.2.0
type RestrictionCard struct {
Name string `json:"name"`
CardNumbers []string `json:"cardNumbers"`
IsNew bool `json:"isNew,omitempty"`
}
RestrictionCard describes one named card entry within a restriction group. CardNumbers may contain multiple printings that share the same rule.
type RestrictionGroup ¶ added in v0.2.0
type RestrictionGroup struct {
// Type is the normalized restriction category.
Type RestrictionType `json:"type"`
// Label preserves the original restriction label text from the source page.
Label string `json:"label"`
// Updated reports whether the source label marked this rule as updated.
Updated bool `json:"updated,omitempty"`
// MaxCopies is the maximum number of copies allowed by this rule, when one
// is explicitly defined.
MaxCopies int `json:"maxCopies,omitempty"`
// ChooseOneOf is the size of a choice-restriction set, when specified.
ChooseOneOf int `json:"chooseOneOf,omitempty"`
// Cards are the card entries covered by this rule.
Cards []RestrictionCard `json:"cards"`
// Notes contains parser-preserved notes attached to this rule.
Notes []string `json:"notes,omitempty"`
// SourceLanguage identifies which language site the rule was parsed from.
SourceLanguage string `json:"sourceLanguage"`
// SourceURL is the rules page that produced this rule.
SourceURL string `json:"sourceURL"`
}
RestrictionGroup describes one normalized restriction rule parsed from the official rules pages.
type RestrictionType ¶ added in v0.2.0
type RestrictionType string
RestrictionType classifies a deck-building rule applied to one or more cards.
const ( RestrictionTypeUnrestricted RestrictionType = "unrestricted" RestrictionTypeRestricted RestrictionType = "restricted" RestrictionTypeLimited RestrictionType = "limited" RestrictionTypeChoiceRestriction RestrictionType = "choice_restriction" RestrictionTypeAnyCombination RestrictionType = "any_combination" )
type Side ¶ added in v0.2.0
type Side string
Side identifies whether a card or title group belongs to the Weiss or Schwarz side.
type SiteLanguage ¶
var ( English SiteLanguage = SiteLanguage(language.English) Japanese SiteLanguage = SiteLanguage(language.Japanese) )
func (SiteLanguage) String ¶ added in v0.1.2
func (s SiteLanguage) String() string
type TitleDeckGroup ¶ added in v0.2.0
type TitleDeckGroup struct {
// CanonicalName is the normalized title family name for this group.
CanonicalName string `json:"canonicalName"`
// Side is the side this group belongs to: "W" for Weiss or "S" for Schwarz.
Side Side `json:"side"`
// AllowedCodes are the set/title codes that may be used in this group.
AllowedCodes []string `json:"allowedCodes"`
// Aliases contains alternate labels for the same title family.
Aliases []string `json:"aliases"`
// SourceLanguage identifies which language site the row was parsed from.
SourceLanguage string `json:"sourceLanguage"`
// SourceTitle preserves the original title text from the source row.
SourceTitle string `json:"sourceTitle"`
// SourceURL is the rules page that produced this group.
SourceURL string `json:"sourceURL"`
// Notes contains parser-preserved context from the source row when useful,
// such as side-selection notes from the Japanese rules page.
Notes []string `json:"notes,omitempty"`
}
TitleDeckGroup describes one side-specific deck-construction grouping from the official rules pages.
A group represents the set/title codes that may be mixed together for one title family on one side. CanonicalName is the normalized family name used by this scraper, while Aliases preserves alternate labels that should resolve to the same family. AllowedCodes are not globally unique: the same code may legally appear in multiple groups if the official rules list it that way.
type Trigger ¶ added in v0.2.1
type Trigger string
Trigger identifies a climax trigger icon.
const ( TriggerSoul Trigger = "SOUL" TriggerComeback Trigger = "COMEBACK" TriggerDraw Trigger = "DRAW" TriggerPool Trigger = "POOL" TriggerTreasure Trigger = "TREASURE" TriggerShot Trigger = "SHOT" TriggerReturn Trigger = "RETURN" TriggerGate Trigger = "GATE" TriggerStandby Trigger = "STANDBY" TriggerChoice Trigger = "CHOICE" TriggerDiscovery Trigger = "DISCOVERY" TriggerChance Trigger = "CHANCE" )