• Stars
    star
    224
  • Rank 177,792 (Top 4 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

spinner

Go (golang) package with 90 configurable terminal spinner/progress indicators.
Go
2,150
star
2

simple-httpd

Drop-in replacement for Python SimpleHTTPServer. Provides TLS via Let's Encrypt over HTTP2, and auto generated self-signed certificates.
Go
230
star
3

sky-island

FaaS platform for running raw Go functions.
Go
117
star
4

jail

Package jail provides native FreeBSD Jail syscalls in Go
Go
52
star
5

super-hacker

SuperHacker is the ultimate utility to make you look like a hacker.
Go
50
star
6

libspinner

A pure C single-header library with 90 configurable terminal spinner/progress indicators.
C
29
star
7

remindme

Go
28
star
8

todo-view

Extract info from TODO's in your code from formatted TODO comments
Go
27
star
9

liblogger

A simple and performant, single-header JSON structured logger for C applications.
C
16
star
10

GoPasswordUtilities

Simple library for working with passwords in Go (golang).
Go
13
star
11

pass

Simple CLI Password Manager
C
12
star
12

flotsam

Project Generator and Dependency Manager for C.
C++
11
star
13

heads-up

A simple example of using Tile38 to track the ISS and send notifications when it's overhead.
Go
10
star
14

presentations

Public repo for my slides
Go
9
star
15

simple-map

A simple and dynamic hash map in C.
C++
9
star
16

stockwatcher

A CLI application to monitor one or more stocks.
Go
7
star
17

smile

Smile. Why not?
Go
7
star
18

libdotenv

libdotenv is a C single-headerlibrary providing the ability to load values from a .env file into environment variables.
C
6
star
19

recipes

A collection of recipes I've created, found, and have been given.
6
star
20

struCtured-logger

A simple JSON structured logger for C applications.
C++
6
star
21

raceway

OpenStack Rally Job Controller
Go
6
star
22

roam-client

Roam by Tile38 API Client
Go
6
star
23

neustar

Package neustar is a SDK to access and work with the Neustar API
Go
5
star
24

cgo_calc

IGNORE. Meant as a descripton of some tech for ${DAY_JOB}
Go
5
star
25

nlog

Structured Logging for Nim
Nim
5
star
26

libmap

A simple map implementation in C
C
5
star
27

libweyl

Middle Random Weyl Sequence
C++
4
star
28

aion

WIP - Job and Task Scheduler Utilizing Cron Syntax
Go
4
star
29

ip

Go
4
star
30

pyopenvswitch

Python module to control and interact with Open vSwitch switches.
Python
2
star
31

doom-fire-c

C
2
star
32

stock-exchange

Go
2
star
33

libbenchmark

loads is a simple library to benchmark C functions across a given number of threads.
C++
2
star
34

mapledb

2
star
35

down-low

down-low is a secure messaging system written in Go (golang) with the ability to send AES and RSA encrypted messages to a number of different endpoints.
Go
2
star
36

games

Terminal games written in Go (golang)
Go
2
star
37

wanbli

1
star
38

gen-release-notes

Go
1
star
39

vms

Shell
1
star
40

kahless

Makefile
1
star
41

gail

Go
1
star
42

jail-builder

Go
1
star
43

logcolor

Go
1
star
44

dictu_modules

C
1
star
45

formatifier

formatifier is a Go (golang) package to quickly format strings in common formats.
Go
1
star
46

daily_tracker

C
1
star
47

r_time

C library providing the ability to get time from remote servers.
C
1
star
48

pwc

Pascal
1
star
49

anagram-primes

C
1
star
50

dictum

Makefile
1
star
51

itsnotgolang

Go
1
star
52

micro-chat

C
1
star
53

dictu.vim

Vim Script
1
star
54

Felix

Felix is an application to be run on Asterisk servers and Kamalio servers when there's an environment needing a process to register in and out carriers and Asterisk servers from the cluster.
Java
1
star
55

fips_dockerfiles

Dockerfile
1
star