Documentation ¶
Overview ¶
Package mtgban defines interfaces for scrapers and utility functions to obtain pricing information from various vendors.
Index ¶
- Constants
- Variables
- func BuylistAdd(buylist map[string]BuylistEntry, card BuylistEntry) error
- func GetExchangeRate(currency string) (float64, error)
- func InventoryAdd(inventory map[string][]InventoryEntry, card InventoryEntry) error
- func SplitVariants(str string) []string
- func WriteArbitrageToCSV(arbitrage []ArbitEntry, w io.Writer) error
- func WriteBuylistToCSV(vendor Vendor, w io.Writer) error
- func WriteCombineToCSV(root *CombineRoot, w io.Writer) error
- func WriteInventoryToCSV(seller Seller, w io.Writer) error
- func WriteMismatchToCSV(mismatch []MismatchEntry, w io.Writer) error
- type ArbitEntry
- type ArbitOpts
- type BanClient
- func (bc *BanClient) Load() error
- func (bc *BanClient) Register(scraper Scraper)
- func (bc *BanClient) ScraperByName(shorthand string) (Scraper, error)
- func (bc *BanClient) Scrapers() (scrapers []Scraper)
- func (bc *BanClient) Sellers() (sellers []Seller)
- func (bc *BanClient) Vendors() (vendors []Vendor)
- type BaseBuylist
- type BaseInventory
- type BuylistEntry
- type Card
- type CombineEntry
- type CombineRoot
- type InventoryEntry
- type LogCallbackFunc
- type MismatchEntry
- type Normalizer
- type NumberCheckFunc
- type Scraper
- type ScraperInfo
- type Seller
- type SetCheckFunc
- type Vendor
Constants ¶
const DefaultArbitMinDiff = 0.2
const DefaultArbitMinSpread = 25.0
const DefaultMismatchMinDiff = 1.0
const DefaultMismatchMinSpread = 100.0
Variables ¶
var ( // The canonical header that will be present in all inventory files InventoryHeader = []string{ "Key", "Name", "Set", "F/NF", "Conditions", "Price", "Quantity", } // The canonical header that will be present in all buylist files BuylistHeader = []string{ "Key", "Name", "Set", "F/NF", "Conditions", "Buy Price", "Trade Price", "Quantity", "Price Ratio", "Quantity Ratio", } ArbitHeader = []string{ "Key", "Name", "Edition", "F/NF", "Conditions", "Sell Price", "Buy Price", "Trade Price", "Difference", "Spread", "Price Ratio", "Quantity Ratio", } MismatchHeader = []string{ "Key", "Name", "Edition", "F/NF", "Conditions", "Price", "Difference", "Spread", } )
var EditionTable = map[string]string{}/* 198 elements not displayed */
var VariantsTable = map[string]map[string]map[string]string{
"Alliances": allVariants,
"Anthologies": athVariants,
"Antiquities": atqVariants,
"Arena League 2001": pal01Variants,
"Asia Pacific Land Program": palpVariants,
"Battle Royale Box Set": brbVariants,
"Champions of Kamigawa": chkVariants,
"Chronicles": chrVariants,
"Collectors’ Edition": oldLandVariants,
"Conspiracy: Take the Crown": cn2Variants,
"Deckmasters": dkmVariants,
"European Land Program": pelpVariants,
"Fallen Empires": femVariants,
"Fifth Edition": ed5Variants,
"Fourth Edition": ed4Variants,
"GRN Ravnica Weekend": prwkVariants,
"Homelands": hmlVariants,
"Ice Age": iceVariants,
"Intl. Collectors’ Edition": oldLandVariants,
"Introductory Two-Player Set": itpVariants,
"Limited Edition Alpha": leaVariants,
"Limited Edition Beta": oldLandVariants,
"Magic Premiere Shop 2005": pmpsVariants,
"Mirage": mirVariants,
"Oath of the Gatewatch": ogwVariants,
"Planeshift": plsVariants,
"Portal Second Age": po2Variants,
"Portal": porVariants,
"Pro Tour Collector Set": ptcVariants,
"Rinascimento": rinVariants,
"RNA Ravnica Weekend": prw2Variants,
"Revised Edition": ed3Variants,
"Secret Lair Drop": sldVariants,
"Shadows over Innistrad": soiVariants,
"Shadows over Innistrad Promos": psoiVariants,
"Tempest": tmpVariants,
"Unlimited Edition": oldLandVariants,
"Unstable": ustVariants,
"World Championship Decks 1999": wc99Variants,
"World Championship Decks 2000": wc00Variants,
"World Championship Decks 2001": wc01Variants,
"World Championship Decks 2002": wc02Variants,
}
Functions ¶
func BuylistAdd ¶
func BuylistAdd(buylist map[string]BuylistEntry, card BuylistEntry) error
func GetExchangeRate ¶
func InventoryAdd ¶
func InventoryAdd(inventory map[string][]InventoryEntry, card InventoryEntry) error
func SplitVariants ¶
SplitVariants returns an array of strings from the parentheses-defined fields commonly used to distinguish some cards across editions.
func WriteArbitrageToCSV ¶
func WriteArbitrageToCSV(arbitrage []ArbitEntry, w io.Writer) error
func WriteCombineToCSV ¶
func WriteCombineToCSV(root *CombineRoot, w io.Writer) error
func WriteMismatchToCSV ¶
func WriteMismatchToCSV(mismatch []MismatchEntry, w io.Writer) error
Types ¶
type ArbitEntry ¶
type ArbitEntry struct { BuylistEntry InventoryEntry Difference float64 Spread float64 }
type BanClient ¶
type BanClient struct {
// contains filtered or unexported fields
}
BanClient abstracts some common operations that can be performed on both Seller and Vendor types, as well as offering a way to retrieve any given Scaper.
func (*BanClient) Load ¶
Load inventory and buylist content for each scraper registered in the client
func (*BanClient) ScraperByName ¶
Return the scraper with a matching name from the ones registered in the client
type BaseBuylist ¶
type BaseBuylist struct {
// contains filtered or unexported fields
}
func (*BaseBuylist) Buylist ¶
func (bl *BaseBuylist) Buylist() (map[string]BuylistEntry, error)
func (*BaseBuylist) Grading ¶
func (bl *BaseBuylist) Grading(entry BuylistEntry) map[string]float64
func (*BaseBuylist) Info ¶
func (inv *BaseBuylist) Info() (info ScraperInfo)
type BaseInventory ¶
type BaseInventory struct {
// contains filtered or unexported fields
}
func (*BaseInventory) Info ¶
func (inv *BaseInventory) Info() (info ScraperInfo)
func (*BaseInventory) Inventory ¶
func (inv *BaseInventory) Inventory() (map[string][]InventoryEntry, error)
type BuylistEntry ¶
type BuylistEntry struct { Card Quantity int Conditions string BuyPrice float64 TradePrice float64 PriceRatio float64 QuantityRatio float64 Notes string }
BuylistEntry represents an entry for buying a particular Card
func LoadBuylistFromCSV ¶
func LoadBuylistFromCSV(r io.Reader) ([]BuylistEntry, error)
type Card ¶
type Card struct { // The unique identifier of a card. When the UUID can be used to associate // two versions of the same card (for example because one is foil), `_f` // suffix is appended to it. Id string `json:"id"` // The official name of the card Name string `json:"name"` // The set the card comes from Set string `json:"set"` // Whether the card is foil or not Foil bool `json:"foil"` }
Card is a generic card representation using fields defined by the MTGJSON project.
type CombineEntry ¶
type CombineRoot ¶
type CombineRoot struct { Names []string Entries map[Card][]CombineEntry BestOffer map[Card]CombineEntry }
func CombineBuylists ¶
func CombineBuylists(vendors []Vendor, useCredit bool) (*CombineRoot, error)
func CombineInventories ¶
func CombineInventories(sellers []Seller) (*CombineRoot, error)
type InventoryEntry ¶
InventoryEntry represents an entry for selling a particular Card
func LoadInventoryFromCSV ¶
func LoadInventoryFromCSV(r io.Reader) ([]InventoryEntry, error)
type LogCallbackFunc ¶
type LogCallbackFunc func(format string, a ...interface{})
type MismatchEntry ¶
type MismatchEntry struct { InventoryEntry Difference float64 Spread float64 }
type Normalizer ¶
type Normalizer struct {
// contains filtered or unexported fields
}
Type to normalize the various name differences across vendors
func NewNormalizer ¶
func NewNormalizer() *Normalizer
NewNormalizer initializes a Normalizer with default rules.
func (*Normalizer) Normalize ¶
func (n *Normalizer) Normalize(str string) string
Normalize uses the rules defined in NewNormalized to replace uncommon elements of card names, producing an easy to compare string.
type Scraper ¶
type Scraper interface {
Info() ScraperInfo
}
Scraper is the interface both Sellers and Vendors need to implement
type ScraperInfo ¶
type ScraperInfo struct { Name string Shorthand string InventoryTimestamp time.Time BuylistTimestamp time.Time }
ScraperInfo contains
type Seller ¶
type Seller interface { // Return the inventory for a Seller. If not already loaded, it will start // scraping the seller gathering the necessary data. Inventory() (map[string][]InventoryEntry, error) // Return some information about the seller Info() ScraperInfo }
Seller is the interface describing actions to be performed on an seller inventory
type SetCheckFunc ¶
type Vendor ¶
type Vendor interface { // Return the buylist for a Vendor. If not already loaded, it will start // scraping the vendor gathering the necessary data. Buylist() (map[string]BuylistEntry, error) // Return the grading scale for adjusting prices according to conditions Grading(BuylistEntry) map[string]float64 // Return some information about the vendor Info() ScraperInfo }
Vendor is the interface describing actions to be performed on an vendor buylist