Created
April 4, 2014 14:49
-
-
Save sanatgersappa/9976221 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"html/template" | |
"os" | |
) | |
type DataPoint struct { | |
Time float64 | |
Summary string | |
Icon string | |
SunriseTime float64 | |
SunsetTime float64 | |
PrecipIntensity float64 | |
PrecipIntensityMax float64 | |
PrecipIntensityMaxTime float64 | |
PrecipProbability float64 | |
PrecipType string | |
PrecipAccumulation float64 | |
Temperature float64 | |
TemperatureMin float64 | |
TemperatureMinTime float64 | |
TemperatureMax float64 | |
TemperatureMaxTime float64 | |
DewPoint float64 | |
WindSpeed float64 | |
WindBearing float64 | |
CloudCover float64 | |
Humidity float64 | |
Pressure float64 | |
Visibility float64 | |
Ozone float64 | |
} | |
type Forecast struct { | |
Latitude float64 | |
Longitude float64 | |
Timezone string | |
Offset float64 | |
Currently DataPoint | |
Junk string | |
} | |
func main() { | |
f := []Forecast{ | |
{18.5204303, 73.8567437, "Asia/Kolkata", 5.5, DataPoint{1.396582827e+09, "Mostly Cloudy", "partly-cloudy-day", 0, 0, 0, 0, 0, 0, "0", 28.19, 0, 0, 0, 0, 5.79, 10.32, 72, 0.83, 0.24, 1010.78, 0, 261.09, 0}, ""}, | |
{35.9250637, -86.8688899, "America/Chicago", -5, DataPoint{1.396582827e+09, "Mostly Cloudy", "partly-cloudy-night", 0, 0, 0, 0, 0, 0, "0", 21.64, 0, 0, 0, 0, 16.59, 20.76, 175, 0.87, 0.73, 1009.73, 14.58, 292.31, 0}, ""}, | |
{-33.8674869, 151.2069902, "Australia/Sydney", 11, DataPoint{1.396582828e+09, "Light Rain", "rain", 0, 0, 0.3683, 0, 0, 0.84, "rain", 0, 21.9, 0, 0, 0, 0, 18.59, 12.97, 172, 0.78, 0.82, 1016.2, 9.99, 248.87}, ""}, | |
{17.9454864, 102.620515, "Asia/Vientiane", 7, DataPoint{1.396582827e+09, "Light Rain", "rain", 0, 0, 0.4648, 0, 0, 0.59, "rain", 0, 31.5, 0, 0, 0, 0, 23.02, 7.89, 105, 0.89, 0.61, 1012.39, 2.99, 261.42}, ""}, | |
} | |
var displayTemplateHTML = ` | |
<table> | |
<thead> | |
<tr> | |
<th>Timezone</th> | |
<th>Temperature</th> | |
<th>Summary</th> | |
</tr> | |
</thead> | |
<tbody> | |
{{range .}} | |
<tr> | |
<td>{{.Timezone}}</td> | |
<td>{{.Currently.Temperature}}</td> | |
<td>{{.Currently.Summary}}</td> | |
</tr> | |
{{ end }} | |
</tbody> | |
</table> | |
` | |
var displayTemplate = template.Must(template.New("display").Parse(displayTemplateHTML)) | |
displayTemplate.Execute(os.Stdout, f) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I figured that out and fixed it. Thanks Sanat.