Documentation
¶
Overview ¶
Package cexfind searches for devices for sale at Cex/Webuy via the unofficial "webuy.io" query endpoint which responds in a json format.
Queries are required to be made in the UK as the endpoint is protected by region-sensitive CDN.
Multiple concurrent queries are supported, with an optional "strict" flag to constrain results to the query terms. The results are a union of the results of each query, ordered by model name and then the price of each item.
Example usage:
postcode := "S10 1LT" // royal armouries museum, leeds
kit := cex.NewCex()
cex.Search(queries, strict, postcode)
results, err := kit.Search(queries, strict)
if err != nil {
log.Fatal(err)
}
latestModel := ""
for _, box := range results {
if box.Model != latestModel {
fmt.Printf("\n%s\n", box.Model)
latestModel = box.Model
}
fmt.Printf(
" £%3d %s\n %s\n %s\n",
box.Price,
box.Name,
box.IDUrl(),
box.StoresString(100), // up to 100 chars of store info
)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // URL is the Cex/Webuy search endpoint URL = "https://search.webuy.io/1/indexes/*/queries" // no results sentinel error NoResultsFoundError error = errors.New("no results found") )
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct {
Model string
Name string
Category string
ID string
Price decimal.Decimal
PriceCash decimal.Decimal
PriceExchange decimal.Decimal
Stores []location.StoreWithDistance
// contains filtered or unexported fields
}
Box is a very simplified representation of a Cex/Webuy json entry, where each entry represents a "Box" or computer or other item for sale.
func (Box) IDUrl ¶ added in v0.2.0
IDUrl returns the full url path to the Cex/Webuy webpage showing the Box (the item of equipment) in question.
func (*Box) StoresString ¶ added in v0.2.5
StoresString returns the stores as a comma delimited string to roughly length, truncating with "…" where necessary. Giving StoreString an argument length of -1 means there is no limit on the length of the returned string.
type CexFind ¶ added in v0.2.8
type CexFind struct {
// contains filtered or unexported fields
}
CexFind provides the means for searching Cex's API with store location data.
func NewCexFind ¶ added in v0.2.8
func NewCexFind() *CexFind
NewCexFind makes a new Cex instance. This should only be initalised once due to caching in the location submodules.
func (*CexFind) LocationDistancesOK ¶ added in v0.3.0
LocationDistancesOK indicates if the storeDistances.store has been initialised and distances can be calculated. If the func returns false then store distances won't be calculated, a fact that client apps should probably report.
func (*CexFind) Search ¶ added in v0.2.8
Search searches the Cex json endpoint at URL for the provided queries, returning a slice of Box or error.
The strict flag ensures that the results contain terms from the search queries as the non-strict results include additional suggestions from the Cex/Webuy system.
The postcode, if provided, allows distances to be calculated from each store if the store data has already been retrieved (store data is retrieved asynchronously).
Multiple queries are run concurrently and their results sorted by model, then by price ascending. Duplicate results are removed at aggregation.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd provides a common query input checker used by the console and web commands.
|
cmd provides a common query input checker used by the console and web commands. |
|
This package has been copied from https://github.com/umahmood/haversine/blob/master/haversine.go to avoid an import.
|
This package has been copied from https://github.com/umahmood/haversine/blob/master/haversine.go to avoid an import. |