meteociel

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

README

Meteociel

This repository and code was created as a result of a personal need to have access to high quality weather data and specifically forecasts for my projects. Having searched for a long time for a French weather API, I finally decided to create a library to get weather information from a well known French site, meteociel.fr. Note that the data is not retrieved via a standard API - not existing -, but via a scraping process to retrieve data from HTML pages.

Examples

Get weather forecast for a city
package main

import (
	"fmt"
	"log"
	"strconv"
	
	"github.com/romitou/meteociel"
)

func main() {
	client := meteociel.CreateClient()
	station, err := client.GetStationForCity("75000")
	if err != nil {
		log.Fatal(err)
	}

	forecasts, err := client.GetForecast(meteociel.ForecastGFS, station)
	if err != nil {
		log.Fatal(err)
	}

	for _, forecast := range forecasts {
		log.Println("Here is the forecast for " + forecast.Time.String() + ":")
		log.Println("  - Weather: " + forecast.Weather.Name)
		log.Println("  - Temperature: " + strconv.Itoa(int(forecast.Temperature)) + "°C")
		log.Println("  - Wind direction: " + strconv.Itoa(int(forecast.WindDirection)) + "°")
		log.Println("  - Wind speed: " + strconv.Itoa(int(forecast.WindSpeed)) + " km/h")
		log.Println("  - Wind gust: " + strconv.Itoa(int(forecast.WindGust)) + " km/h")
		log.Println("  - Rainfall: " + fmt.Sprint(forecast.Rainfall) + " mm")
		log.Println("  - Humidity: " + strconv.Itoa(int(forecast.Humidity)) + "%")
		log.Println("  - Pressure: " + strconv.Itoa(int(forecast.Pressure)) + " hPa")

	}

}

Documentation

Index

Constants

View Source
const MeteocielHourFormat = "15:04"

Variables

View Source
var MeteocielDays = []string{"Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"}
View Source
var WeatherTypes = map[string]WeatherType{
	"soleil": {
		Name: "Sunny",
	},
	"voile": {
		Name: "Little cloudy",
	},
	"peu_nuageux": {
		Name: "Partly cloudy",
	},
	"mitige": {
		Name: "Mixed",
	},
	"nuageux": {
		Name: "Cloudy",
	},
	"brouillard": {
		Name: "Foggy",
	},
	"pluie": {
		Name: "Rainy",
	},
	"grele": {
		Name: "Hail",
	},
	"neige": {
		Name: "Snowy",
	},
	"averse_pluiefaible": {
		Name: "Light rain shower",
	},
	"averse_pluie": {
		Name: "Rain shower",
	},
	"averse_neige": {
		Name: "Snow shower",
	},
	"averse_orage": {
		Name: "Thunderstorm",
	},
	"averse_pluieneige": {
		Name: "Rain and snow shower",
	},
	"pluie_neige": {
		Name: "Rain and snow",
	},
	"oragefaible": {
		Name: "Major thunderstorm",
	},
}

Functions

This section is empty.

Types

type ForecastType

type ForecastType string
const (
	ForecastGFS       ForecastType = "https://www.meteociel.fr/previsions/{stationId}/{station}.htm"
	ForecastWRF       ForecastType = "https://www.meteociel.fr/previsions-wrf/{stationId}/{station}.htm"
	ForecastWRF1H     ForecastType = "https://www.meteociel.fr/previsions-wrf-1h/{stationId}/{station}.htm"
	ForecastAROME     ForecastType = "https://www.meteociel.fr/previsions-arome/{stationId}/{station}.htm"
	ForecastAROME1H   ForecastType = "https://www.meteociel.fr/previsions-arome-1h/{stationId}/{station}.htm"
	ForecastARPEGE1H  ForecastType = "https://www.meteociel.fr/previsions-arpege-1h/{stationId}/{station}.htm"
	ForecastICONEU    ForecastType = "https://www.meteociel.fr/previsions-iconeu/{stationId}/{station}.htm"
	ForecastICOND2    ForecastType = "https://www.meteociel.fr/previsions-icond2/{stationId}/{station}.htm"
	ForecastTrends10J ForecastType = "https://www.meteociel.fr/tendances/{stationId}/{station}.htm"
)

type MeteocielClient

type MeteocielClient struct {
	HttpClient http.Client
}

MeteocielClient This struct represents a Meteociel client.

func CreateClient

func CreateClient() *MeteocielClient

CreateClient This method creates a new Meteociel client.

func (MeteocielClient) GetForecast

func (client MeteocielClient) GetForecast(forecast ForecastType, station MeteocielStation) (forecasts []MeteocielForecast, err error)

GetForecast This method returns the forecast for a given station. Depending on the type of forecast you have chosen, the data may be different and some elements may not be present.

func (MeteocielClient) GetStationForCity

func (client MeteocielClient) GetStationForCity(exactName string) (station MeteocielStation, err error)

GetStationForCity This method returns the Meteociel station for a given city. You MUST provide the exact ZIP code or the name of the city, otherwise the method will return an error.

type MeteocielForecast

type MeteocielForecast struct {
	Time          time.Time
	Temperature   int8
	WindDirection int16

	WindSpeed int8
	WindGust  int8

	Rainfall float32
	Humidity int8

	Pressure int16
	Weather  WeatherType
}

type MeteocielStation

type MeteocielStation struct {
	ID   string
	Name string
}

MeteocielStation This struct represents a Meteociel station. You can use it to get forecasts for a given station.

type StationEndpoint

type StationEndpoint string
const (
	StationSearch StationEndpoint = "https://www.meteociel.fr/prevville.php?action=getville&villeid=&ville={city}&envoyer=OK"
)

type WeatherType

type WeatherType struct {
	Name string
}

Jump to

Keyboard shortcuts

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