cexfind

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 12 Imported by: 0

README

cexfind

A Go module with console, cli and web app clients for rapid and effective searches for equipment on 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).

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 for the very simple cexfind golang module:

console

A bubbletea console app.

Have a look at the README for the console app 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.

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.)

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:

results, err := cex.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",
		box.Price,
		box.Name,
		box.IDUrl(),
	)
}

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"
)

Functions

This section is empty.

Types

type Box

type Box struct {
	Model string
	Name  string
	ID    string
	Price int
}

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 Search(queries []string, strict bool) ([]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.

Multiple queries are run concurrently and their results sorted by model, then by price ascending. Duplicate results are removed at aggregation.

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.

Jump to

Keyboard shortcuts

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