Giter Site home page Giter Site logo

szaydel / openweathermap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from briandowns/openweathermap

0.0 3.0 0.0 781 KB

Go (golang) package for use with openweathermap.org's API.

License: Apache License 2.0

Makefile 0.36% Go 98.26% HTML 1.38%

openweathermap's Introduction

OpenWeatherMap Go API

GoDoc Build Status Coverage Status

Go (golang) package for use with openweathermap.org's API.

For more detail about the library and its features, reference your local godoc once installed.

Website!

To use the OpenweatherMap API, you need to obtain an API key. Sign up here. Once you have your key, create an environment variable called OWM_API_KEY. Start coding!

Slack Channel

Contributions welcome!

Features

Current Weather Conditions

  • By City
  • By City,St (State)
  • By City,Co (Country)
  • By City ID
  • By Zip,Co (Country)
  • By Longitude and Latitude

Forecast

Get the weather conditions for a given number of days.

  • By City
  • By City,St (State)
  • By City,Co (Country)
  • By City ID
  • By Longitude and Latitude

Access to Condition Codes and Icons

Gain access to OpenWeatherMap icons and condition codes.

  • Thunderstorms
  • Drizzle
  • Rain
  • Snow
  • Atmosphere
  • Clouds
  • Extreme
  • Additional

Data Available in Multiple Measurement Systems

  • Fahrenheit (OpenWeatherMap API - imperial)
  • Celsius (OpenWeatherMap API - metric)
  • Kelvin (OpenWeatherMap API - internal)

UV Index Data

  • Current
  • Historical

Pollution Data

  • Current

Historical Conditions

  • By Name
  • By ID
  • By Coordinates

Supported Languages

English - en, Russian - ru, Italian - it, Spanish - es (or sp), Ukrainian - uk (or ua), German - de, Portuguese - pt, Romanian - ro, Polish - pl, Finnish - fi, Dutch - nl, French - fr, Bulgarian - bg, Swedish - sv (or se), Chinese Traditional - zh_tw, Chinese Simplified - zh (or zh_cn), Turkish - tr, Croatian - hr, Catalan - ca

Installation

go get github.com/briandowns/openweathermap

Examples

There are a few full examples in the examples directory that can be referenced. 1 is a command line application and 1 is a simple web application.

package main

import (
	"log"
	"fmt"
	"os"

	// Shortening the import reference name seems to make it a bit easier
	owm "github.com/briandowns/openweathermap"
)

var apiKey = os.Getenv("OWM_API_KEY")

func main() {
	w, err := owm.NewCurrent("F", "ru", apiKey) // fahrenheit (imperial) with Russian output
	if err != nil {
		log.Fatalln(err)
	}

	w.CurrentByName("Phoenix")
	fmt.Println(w)
}

Current Conditions by location name

func main() {
    w, err := owm.NewCurrent("K", "EN", apiKey) // (internal - OpenWeatherMap reference for kelvin) with English output
    if err != nil {
        log.Fatalln(err)
    }

    w.CurrentByName("Phoenix,AZ")
    fmt.Println(w)
}

Forecast Conditions in imperial (fahrenheit) by coordinates

func main() {
    w, err := owm.NewForecast("5", "F", "FI", apiKey) // valid options for first parameter are "5" and "16"
    if err != nil {
        log.Fatalln(err)
    }

    w.DailyByCoordinates(
        &owm.Coordinates{
                Longitude: -112.07,
                Latitude: 33.45,
        },
        5 // five days forecast
    )
    fmt.Println(w)
}

Current conditions in metric (celsius) by location ID

func main() {
    w, err := owm.NewCurrent("C", "PL", apiKey)
    if err != nil {
        log.Fatalln(err)
    }

    w.CurrentByID(2172797)
    fmt.Println(w)
}

Current conditions by zip code. 2 character country code required

func main() {
    w, err := owm.NewCurrent("F", "EN", apiKey)
    if err != nil {
        log.Fatalln(err)
    }

    w.CurrentByZip(19125, "US")
    fmt.Println(w)
}

Configure http client

func main() {
    client := &http.Client{}
    w, err := owm.NewCurrent("F", "EN", apiKey, owm.WithHttpClient(client))
    if err != nil {
        log.Fatalln(err)
    }
}

Current UV conditions

func main() {
    uv, err := owm.NewUV(apiKey)
    if err != nil {
        log.Fatalln(err)
    }

    coord := &owm.Coordinates{
        Longitude: 53.343497,
        Latitude:  -6.288379,
    }

    if err := uv.Current(coord); err != nil {
        log.Fatalln(err)
    }
    
    fmt.Println(coord)
}

Historical UV conditions

func main() {
    uv, err := owm.NewUV(apiKey)
    if err != nil {
        log.Fatalln(err)
    }

    coord := &owm.Coordinates{
        Longitude: 54.995656,
        Latitude:  -7.326834,
    }

    end := time.Now().UTC()
    start := time.Now().UTC().Add(-time.Hour * time.Duration(24))

    if err := uv.Historical(coord, start, end); err != nil {
        log.Fatalln(err)
    }
}

UV Information

func main() {
    uv, err := owm.NewUV(apiKey)
    if err != nil {
        log.Fatalln(err)
    }
    
    coord := &owm.Coordinates{
    	Longitude: 53.343497,
    	Latitude:  -6.288379,
    }
    
    if err := uv.Current(coord); err != nil {
    	log.Fatalln(err)
    }

    info, err := uv.UVInformation()
    if err != nil {
        log.Fatalln(err)
    }
    
    fmt.Println(info)
}

Pollution Information

func main() {
    pollution, err := owm.NewPollution(apiKey)
    if err != nil {
        log.Fatalln(err)
    }

    params := &owm.PollutionParameters{
        Location: owm.Coordinates{
            Latitude:  0.0,
            Longitude: 10.0,
        },
        Datetime: "current",
    }

    if err := pollution.PollutionByParams(params); err != nil {
        log.Fatalln(err)
    }
}

One Call Information

func main() {
	// Possibility to exclude information. For example exclude daily information []string{ExcludeDaily}
	w, err := owm.NewOneCall("F", "EN", apiKey, []string{})
	if err != nil {
		log.Fatalln(err)
	}

	err = w.OneCallByCoordinates(
		&Coordinates{
			Longitude: -112.07,
			Latitude:  33.45,
		},
	)
	if err != nil {
		t.Error(err)
	}

	fmt.Println(w)
}

openweathermap's People

Contributors

briandowns avatar tksmaru avatar armon avatar donatj avatar billykwooten avatar yorugac avatar almogbaku avatar bruston avatar 0ry0n avatar jimmykuo avatar zachfi avatar davidprogers avatar penguwin avatar bl4ckcontact avatar ilmanzo avatar partyzanex avatar gendonl avatar mikmuellerdev avatar nevkontakte avatar wing924 avatar clinyong avatar

Watchers

Sam Zaydel avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.