craigslist

package module
v0.0.0-...-975a908 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: MIT Imports: 14 Imported by: 0

README

go-craigslist

Build Status GoDoc

Craigslist.org wrapper for Go

Install

go get -u github.com/sosedoff/go-craigslist

Usage

package main

import (
  "log"

  "github.com/sosedoff/go-craigslist"
)

func main() {
  opts := craigslist.SearchOptions{
    Category: "cto", // cars+trucks
    Query:    "honda",
    HasImage: true,
    MinPrice: 10000,
    MaxPrice: 20000,
  }

  // Perform a search
  result, err := craigslist.Search("chicago", opts)
  if err != nil {
    log.Fatal(err)
  }

  for _, listing := range result.Listings {
    log.Println(listing.JSON())
  }

  // Fetch listing details
  listing, err := craigslist.GetListing(result.Listings[0].URL)
  if err != nil {
    log.Fatal(err)
  }

  log.Println(listing)
}

Test

make test

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultiSearch

func MultiSearch(sites []string, opts SearchOptions) (map[string]*SearchResults, error)

func StartServer

func StartServer(addr string) error

Types

type Image

type Image struct {
	Small  string `json:"small"`
	Medium string `json:"medium"`
	Large  string `json:"large"`
}

type LatLng

type LatLng struct {
	Lat float64 `json:"lat"`
	Lng float64 `json:"lng"`
}

type Listing

type Listing struct {
	Id          string            `json:"id"`
	Title       string            `json:"title"`
	Description string            `json:"description,omitempty"`
	URL         string            `json:"url"`
	Price       int               `json:"price"`
	Images      []Image           `json:"images"`
	Attributes  map[string]string `json:"attributes,omitempty"`
	Location    *LatLng           `json:"location,omitempty"`
	PostedAt    *time.Time        `json:"posted_at,omitempty"`
	UpdatedAt   *time.Time        `json:"updated_at,omitempty"`
}

func GetListing

func GetListing(url string) (*Listing, error)

func ParseListing

func ParseListing(reader io.Reader) (*Listing, error)

func (*Listing) JSON

func (l *Listing) JSON() (string, error)

type SearchOptions

type SearchOptions struct {
	Category         string `form:"category"`
	Query            string `form:"query"`
	TitlesOnly       bool   `form:"titles_only"`
	HasImage         bool   `form:"has_image"`
	PostedToday      bool   `form:"posted_today"`
	BundleDuplicates bool   `form:"bundle_duplicates"`
	IncludeNearby    bool   `form:"include_nearby"`
	MinPrice         int    `form:"min_price"`
	MaxPrice         int    `form:"max_price"`
	Skip             int    `form:"skip"`
	Params           map[string]string
}

type SearchResults

type SearchResults struct {
	RangeFrom  int       `json:"range_from"`
	RangeTo    int       `json:"range_to"`
	TotalCount int       `json:"total_count"`
	Listings   []Listing `json:"listings"`
}

func ParseSearchResults

func ParseSearchResults(reader io.Reader) (*SearchResults, error)
func Search(siteId string, opts SearchOptions) (*SearchResults, error)

type Site

type Site struct {
	Id         string
	Name       string
	RegionId   string
	RegionName string
	URL        string
}

func ParseSites

func ParseSites(reader io.Reader) ([]Site, error)

ParseSites extracts all sites from the reader

func Sites

func Sites() ([]Site, error)

Sites returns all US-based sites

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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