New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/qba73/meteo

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/qba73/meteo

v0.0.0-20240503212640-96a9b721da05
Source
Go
Version published
Created
Source

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

FAQs

Package last updated on 03 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts