-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructured files,use real time temp data
- Loading branch information
1 parent
d56b31e
commit ac1ec91
Showing
5 changed files
with
80 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
type Temperature struct { | ||
Temp float64 `json:"temperature"` | ||
} | ||
|
||
type Final struct { | ||
StartTime string `json:"startTime"` | ||
Values Temperature `json:"values"` | ||
} | ||
|
||
type Interval struct { | ||
Timestep string `json:"timestep"` | ||
StartTime string `json:"startTime"` | ||
EndTime string `json:"endTime"` | ||
TempVal []Final `json:"intervals"` | ||
} | ||
|
||
type Timelines struct { | ||
Timestep []Interval `json:"timelines"` | ||
} | ||
|
||
type Response struct { | ||
Data Timelines `json:"data"` | ||
} | ||
|
||
func getTempData() Response { | ||
url := fmt.Sprintf("https://api.tomorrow.io/v4/timelines?location=%f,%f&fields=temperature×teps=%s&units=%s", 73.98529171943665, 40.75872069597532, "1h", "metric") | ||
|
||
req, _ := http.NewRequest("GET", url, nil) | ||
req.Header.Add("apikey", "APIKEY") | ||
res, _ := http.DefaultClient.Do(req) | ||
defer res.Body.Close() | ||
|
||
body, _ := ioutil.ReadAll(res.Body) | ||
|
||
var dat Response | ||
if err := json.Unmarshal(body, &dat); err != nil { | ||
panic(err) | ||
} | ||
|
||
return dat | ||
} |