ncei

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ncei is the library behind the ncei command line: the HTTP client, request shaping, and the typed data models for NOAA NCEI (National Centers for Environmental Information) historical climate data.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.

Index

Constants

View Source
const BaseURL = "https://www.ncei.noaa.gov/access/services/data/v1"

BaseURL is the root every data request is built from.

View Source
const DefaultUserAgent = "ncei/dev (+https://github.com/tamnd/ncei-cli)"

DefaultUserAgent identifies the client to NCEI.

View Source
const Host = "www.ncei.noaa.gov"

Host is the NCEI hostname.

Variables

View Source
var KnownStations = []KnownStation{
	{ID: "USW00094728", Name: "Central Park", Location: "New York, NY"},
	{ID: "USW00094846", Name: "JFK Airport", Location: "New York, NY"},
	{ID: "USW00013880", Name: "Hartsfield-Jackson Atlanta International Airport", Location: "Atlanta, GA"},
	{ID: "USW00023234", Name: "Los Angeles International Airport", Location: "Los Angeles, CA"},
	{ID: "USW00094741", Name: "O'Hare International Airport", Location: "Chicago, IL"},
	{ID: "USW00023174", Name: "Seattle-Tacoma International Airport", Location: "Seattle, WA"},
}

KnownStations is the built-in lookup table of well-known NCEI station IDs.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to NCEI over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 30s timeout, a 500ms minimum gap between requests, and three retries on transient errors.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.

func (*Client) GetDaily

func (c *Client) GetDaily(ctx context.Context, station, start, end string, limit int) ([]DailyRecord, error)

GetDaily fetches daily climate summaries for the given station and date range. The limit parameter caps results; 0 means no cap.

func (*Client) GetMonthly

func (c *Client) GetMonthly(ctx context.Context, station, start, end string, limit int) ([]MonthlyRecord, error)

GetMonthly fetches monthly climate summaries for the given station and date range. The limit parameter caps results; 0 means no cap.

type Config

type Config struct {
	Rate    time.Duration
	Retries int
	Timeout time.Duration
}

Config holds the tunable client settings returned by DefaultConfig.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns conservative defaults suitable for a public API.

type DailyRecord

type DailyRecord struct {
	Station       string  `json:"station" kit:"id"`
	Date          string  `json:"date"`
	TempMax       float64 `json:"temp_max_c"`
	TempMin       float64 `json:"temp_min_c"`
	TempAvg       float64 `json:"temp_avg_c"`
	Precipitation float64 `json:"precipitation_mm"`
	Snow          float64 `json:"snow_mm"`
}

DailyRecord holds a single daily climate summary for a station.

type Domain

type Domain struct{}

Domain is the NCEI driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns a station ID or keyword into a (type, id) pair.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live NCEI CDO web URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every NCEI operation onto app.

type KnownStation

type KnownStation struct {
	ID       string `json:"id" kit:"id"`
	Name     string `json:"name"`
	Location string `json:"location"`
}

KnownStation is an entry in the built-in station lookup table.

type MonthlyRecord

type MonthlyRecord struct {
	Station       string  `json:"station" kit:"id"`
	Date          string  `json:"date"`
	TempAvg       float64 `json:"temp_avg_c"`
	Precipitation float64 `json:"precipitation_mm"`
	Snow          float64 `json:"snow_mm"`
	WindSpeed     float64 `json:"wind_speed_ms"`
}

MonthlyRecord holds a single monthly climate summary for a station.

Jump to

Keyboard shortcuts

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