예제 #1
0
func (w *weatherCom) dlCurrent() error {
	if !w.DisplayCurrentIcon {
		return nil
	}

	cur := &Current{}
	url := fmt.Sprintf(WeatherComURLBase+WeatherComSuffixCurrent+unitTemp(w.UseCelcius), w.LocationCode)
	e := download.XML(url, cur)
	if e != nil {
		return e
	}

	// Received data is valid, update it.
	w.current = cur
	cur.WeatherDescription = tran.Splug(cur.WeatherDescription)

	// Prepend degree symbol to unit if missing.
	cur.UnitTemp = unitDegree(cur.UnitTemp)

	// Parse sun time.
	cur.TxtSunrise, cur.TxtSunset, cur.IsNight, e = FormatSun(cur.Sunrise, cur.Sunset, w.Time24H)

	// Parse update time.
	upd, e := time.Parse("1/2/06 3:04 PM MST", cur.UpdateTime)
	if e != nil {
		return e
	}
	cur.TxtUpdateTime = upd.Format(timeFormat(w.Time24H))

	return nil
}
예제 #2
0
// FindLocation asks the server the list of locations matching the given name.
//
func FindLocation(locationName string) ([]Loc, error) {
	var search Search
	e := download.XML(WeatherComURLBase+"/search/search?where="+locationName, &search)
	if e != nil {
		return nil, e
	}

	return search.Loc, nil
}
예제 #3
0
func (w *weatherCom) dlForecast() error {
	w.forecast = &Forecast{}
	url := fmt.Sprintf(WeatherComURLBase+WeatherComSuffixForecast+unitTemp(w.UseCelcius), w.LocationCode, w.NbDays+1)
	e := download.XML(url, w.forecast)
	if e != nil {
		return e
	}
	w.forecast.UnitTemp = unitDegree(w.forecast.UnitTemp)

	// Parse day number and sun time.
	for i := range w.forecast.Days {
		day := &w.forecast.Days[i]
		date, e := time.Parse("Jan 2", day.Date)
		if e != nil {
			return e
		}
		day.MonthDay = date.Day()

		day.TxtSunrise, day.TxtSunset, _, e = FormatSun(day.Sunrise, day.Sunset, w.Time24H)
		if e != nil {
			return e
		}

		day.DayName = tran.Splug(day.DayName)
		for i := range day.Part {

			if day.Part[i].WeatherDescription == "" {
				day.Part[i].WeatherDescription = ValueMissing
			} else {
				day.Part[i].WeatherDescription = tran.Splug(day.Part[i].WeatherDescription)
			}
		}
	}

	return nil
}