-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetcher.go
40 lines (33 loc) · 833 Bytes
/
fetcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
owm "github.com/briandowns/openweathermap" // "owm" for easier use
"log"
"os"
)
const maxNumberOfStations int = 60
const lang string = "en"
const units string = "f"
func getStationList() []string {
return []string{
"Seattle",
"Terre-de-Bas",
}
}
// getCurrent gets the current weather for the provided
// location in the units provided.
func getCurrentByName(name string) *owm.CurrentWeatherData {
w, err := owm.NewCurrent(units, lang, os.Getenv("OWM_API_KEY"))
if err != nil {
log.Fatalln(err)
}
w.CurrentByName(name)
return w
}
func getCurrentForEachStation(stations []string) map[string]*owm.CurrentWeatherData {
currentsMap := make(map[string]*owm.CurrentWeatherData)
for _, s := range stations {
current := getCurrentByName(s)
currentsMap[s] = current
}
return currentsMap
}