carousell

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package carousell provides primitives for querying Carousell (Singapore) and parsing the listings programatically.

It also provides a simple caching mechanism for users to store state on the listings, for example, only caching after post-processing of a listing is completed successfully.

Index

Constants

View Source
const ENDPOINT = "https://www.carousell.sg"

Variables

This section is empty.

Functions

func ShortenListings

func ShortenListings(l []Listing) []string

ShortenListings return a summarized output of a list of listings.

func WithPriceCeil

func WithPriceCeil(px int) func(r *Req)

func WithPriceFloor

func WithPriceFloor(px int) func(r *Req)

WithPriceFloor adds a filter for price floor.

func WithRecent

func WithRecent(r *Req)

WithRecent ensures that only latest listings are being queried.

func WithSearch

func WithSearch(searchTerm string) func(r *Req)

WithSearch adds a search term to a carousell Request.

Types

type Cache

type Cache struct {
	Alerts map[string]bool
}

A Cache is a structure that includes utilities, to store state on carousell listings after post-processing.

func NewCache

func NewCache() *Cache

Creates a new Cache of carousell alerts.

func (*Cache) ProcessAndStore

func (c *Cache) ProcessAndStore(listings []Listing, cb func(listing Listing) error)

Process accepts a callback that processes a new listing, before storing it in the cache

func (*Cache) Store

func (c *Cache) Store(listings []Listing)

Store is a helper to cache listings by their IDs, to update the state that a listing has been processed.

type Listing

type Listing struct {
	Title       string
	Description string
	Price       float64
	Condition   string
	Url         string
	User        string
	Time        string
	ID          string
}

A Listing is a single carousell post. It contains all the information extracted off a carousell listing.

func (*Listing) Print

func (l *Listing) Print()

Print is a summarized output of a listing printed out to console.

func (*Listing) Sprint

func (l *Listing) Sprint() string

Sprint returns a summarized output of a listing.

type Req

type Req struct {
	// contains filtered or unexported fields
}

A Req is a structure that consists of relevant parameters to encapsulate a carousell GET request

func NewReq

func NewReq(opts ...func(*Req)) *Req

Creates a new carousell blank Request. Modifiers, e.g. WithSearch, are used to add search criteria, before sending out the Request via Get.

func (*Req) Get

func (r *Req) Get() ([]Listing, error)

Get gets and parse carousell listing based on user parameters.

func (*Req) GetSearchTerm

func (r *Req) GetSearchTerm() string

Jump to

Keyboard shortcuts

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