Giter VIP home page Giter VIP logo

meteo's Introduction

Go Reference Go Go Report Card GitHub GitHub go.mod Go version

meteo

Meteo is a Go client library for the weather and meteorological forecast from Yr.

Weather forecast from Yr, delivered by the Norwegian Meteorological Institute and NRK.

Usage

You must register your user agent string in the YR.NO service and your user name at the GeoNames.org.

package main

import (
	"fmt"

	"github.com/qba73/meteo"
)

func main() {
	// Export GEO_USERNAME Env Var (you registered at geonames.org)

	// Get current weather for given location.
	weather, err := meteo.GetWeather("Vilnius,LT")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(weather)
	// Cloudy 4.2°C

	fmt.Println(weather.Summary)
	// cloudy

	fmt.Println(weather.Temp)
	// 4.2
}

The code sample below shows a basic example of how the meteo package can fetch weather statuses concurrently.

package main

import (
	"fmt"
	"time"

	"github.com/qba73/meteo"
)

func main() {
	start := time.Now()
	ch := make(chan string)

	locations := []string{
		"Vilnius,LT", "Dublin,IE", "London,UK", "Berlin,DE",
		"Belfast,UK", "Castlebar,IE", "Killarney,IE",
		"Warsaw,PL", "Lodz,PL", "Vienna,AT"}

	for _, loc := range locations {
		go getWeather(loc, ch)
	}

	for range locations {
		fmt.Println(<-ch)
	}

	fmt.Printf("%.2fs elapsed\n", time.Since(start).Seconds())
}

func getWeather(location string, ch chan<- string) {
	start := time.Now()

	weather, err := meteo.GetWeather(location)
	if err != nil {
		ch <- fmt.Sprint(err)
		return
	}
	sec := time.Since(start).Seconds()
	ch <- fmt.Sprintf("%.2fs Location: %s, Weather: %s", sec, location, weather)
}

Installation

$ go install github.com/qba73/meteo/cmd/meteo@latest

meteo's People

Contributors

dependabot[bot] avatar qba73 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

meteo's Issues

Lookup for a place in multiple countries

At present geonames wikipedia name resolver looks for a place in a single (provided) country. Add ability to lookup for a place with given name in multiple countries.

Prepare package documentation

Write extensive package documentation with examples of how to use it as a library in projects. Doc needs to meet open source Go community standards.

Pass args to CLI

Implement reading args from the cli and passing them to the run funs. Implement multiple options (sources) of input - terminal, file (for scripting) etc.

Add weather forecast lookup for a week

Currently meteo (Norway client) provides info about current weather conditions in a given place. Implement functionality to check for the forecast for X days.

Remove suffix from weather status description

For some locations Yr API returns additional information, like night for example. This happens as the label Partlycloudy_nigh represents in the returned json payload the name of the status icon.
It would be nice to implement a function that trims down the suffix. Other approach may be to check all possible suffix values Yr returns, and to create a custom mapping between returned values from Yr API and Meteo API. meteo could use this mapping to change weather description returned from its API.

Example current output:

0.61s Location: Berlin,DE, Weather: Partlycloudy_night 3.8°C

Expected:

0.61s Location: Berlin,DE, Weather: Partlycloudy 3.8°C

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.