mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-22 12:43:11 -05:00
Added basic weather fetching
This commit is contained in:
parent
b9f3bdfd47
commit
7f08573637
1 changed files with 28 additions and 3 deletions
|
@ -1,9 +1,34 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
func getToday(wg *sync.WaitGroup, cfg *config) {
|
func getCurrent(app *application) {
|
||||||
|
|
||||||
// errMsg := "\nSorry, couldn't get today's weather. Perhaps you've been rate limited?"
|
lat := "lat=" + app.Config.Latitude
|
||||||
|
lon := "&lon=" + app.Config.Longitude
|
||||||
|
units := "&units=" + app.Config.Units
|
||||||
|
key := "&appid=" + app.Config.ApiKey
|
||||||
|
url := "https://pro.openweathermap.org/data/2.5/weather?" + lat + lon + units + key
|
||||||
|
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(body, &app.Forecast)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
app.WaitGroup.Done()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue