From 63006015a66f1704a7e0eebd9392c7ba339c8451 Mon Sep 17 00:00:00 2001 From: simonkellet Date: Sun, 13 Feb 2022 12:04:27 +0000 Subject: [PATCH] intial commit --- go.mod | 3 +++ main.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ stirling.json | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 go.mod create mode 100644 main.go create mode 100644 stirling.json diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9999a3c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go-weather + +go 1.17 diff --git a/main.go b/main.go new file mode 100644 index 0000000..24a8a42 --- /dev/null +++ b/main.go @@ -0,0 +1,57 @@ +package main + +type WeatherAPI struct { + Coord Coord `json:"coord"` + Weather Weather `json:"weather` + Base string `json:"base"` + Main Main `json:"main"` + Visability string `json:"visibility"` + Wind Wind `json:"wind"` + Rain Rain `json:"rain"` + Clouds Cloud `json:"cloud"` + dt DT `json:"dt"` + Sys Sys `json:"sys"` + TimeZone int `json:"timezone"` + ID int `json:"id"` + Name string `json:"name"` + COD int `json:"cod"` +} + +type Coord struct { + //etc +} + +func main() { + /* + //setting up openweathermap api + lat := "56.122970" + lon := "-3.932390" + city := "Stirling, uk" + api_key := "29e5139b86638988d333a28ba360bfd9" + full := "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + api_key + "" + fmt.Printf("\n------\nWeather url: %+s\n---------\n", full) + + //read webpage + url := full + resp, err := http.Get(url) + //reads html as a slice of bytes + html, err := ioutil.ReadAll(resp.Body) + if err != nil { + panic(err) + } + */ + //print the html + //fmt.Printf("%s\n", html) + /* + out, _ := json.Marshal(html) + fmt.Printf("%s\n", out) + */ + /* + byteArray, error := json.MarshalIndent(html, "", " ") + if error != nil { + fmt.Println(err) + } + + fmt.Println(string(byteArray)) + */ +} diff --git a/stirling.json b/stirling.json new file mode 100644 index 0000000..ce3e889 --- /dev/null +++ b/stirling.json @@ -0,0 +1,47 @@ +{ + "coord": { + "lon": -3.9324, + "lat": 56.123 + }, + "weather": [ + { + "id": 502, + "main": "Rain", + "description": "heavy intensity rain", + "icon": "10d" + } + ], + "base": "stations", + "main": { + "temp": 279.55, + "feels_like": 277.93, + "temp_min": 278.39, + "temp_max": 280.56, + "pressure": 991, + "humidity": 95 + }, + "visibility": 4047, + "wind": { + "speed": 2.24, + "deg": 88, + "gust": 4.02 + }, + "rain": { + "1h": 4.86 + }, + "clouds": { + "all": 100 + }, + "dt": 1644753046, + "sys": { + "type": 2, + "id": 2009014, + "country": "GB", + "sunrise": 1644738387, + "sunset": 1644772418 + }, + "timezone": 0, + "id": 2636910, + "name": "Stirling", + "cod": 200 +} \ No newline at end of file