cexfind

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 17 Imported by: 0

README

cexfind

v0.3.0 : 29 January 2025 : add location service unavailability checks

This release exposes location service unavailability in the Cexfind library and apps.

Try it out on GCP!

Find kit on Cex, fast

This project is a Go module with console, cli and web app clients for rapid and effective searches for second hand equipment for sale at Cex/Webuy using the unofficial webuy.io json search endpoint.

Note that these programs only work for queries made in the UK (or via a proxy terminating in the UK). This is intended to be a fun project not intended for commercial use.

Usage

Simply download the binaries for your machine's architecture from releases. Alternatively, build for your local machine using make build-all if you have go (>= 1.22) installed. The resulting binaries can be found in bin.

Clients

Three clients are provided:

web server

A simple htmx webserver client.

Run ./bin/webserver or the windows alternative to run the server locally on the default local ip address of 127.0.0.1 and port 8000. Use the command line switches to change these options. (Use -h to see the switches.)

console

A bubbletea console app.

Have a look at the app README for more info about the architecture of this client.

cli

A simple cli client.

Run ./bin/cli -h or the windows alternative to see the switch options.

Licence

This project is licensed under the MIT Licence.

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

View Source
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

func (b Box) IDUrl() string

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

func (b *Box) StoresString(length int) string

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

func (c *CexFind) LocationDistancesOK() bool

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

func (cex *CexFind) Search(queries []string, strict bool, postcode string) ([]Box, error)

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.

Jump to

Keyboard shortcuts

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