briandowns/openweathermap

Is API key needed

Closed this issue · 4 comments

From the examples, it gets weather data without API key.

The webpage definitely says that. I've never used it and I've never had an issue not using one either. I'll dig a bit further into it to be safe.

Thanks for your reply. I use below to get data

func (this *WeatherModel) Get(city string) (*owm.ForecastWeatherData, error) {
    var days int = 2
    w, err := owm.NewForecast("C", "zh_cn")
    if err != nil {
        goto fail
    }

    err = w.DailyByName(city, days)
    if err != nil {
        goto fail
    }

    return w, nil

fail:
    return nil, err
}

The response is like

{
            "cod": "200",
            "message": 0.0581,
            "city": {
                "id": 1795565,
                "name": "Shenzhen",
                "coord": {
                    "lon": 114.068298,
                    "lat": 22.54554
                },
                "country": "CN",
                "population": 0,
                "sys": {
                    "population": 0
                }
            },
            "cnt": 2,
            "list": [
                {
                    "dt": 1431662400,
                    "temp": {
                        "day": 304.79,
                        "min": 300.26,
                        "max": 304.79,
                        "night": 300.26,
                        "eve": 303.52,
                        "morn": 304.79
                    },
                    "pressure": 1016.96,
                    "humidity": 64,
                    "weather": [
                        {
                            "id": 804,
                            "main": "Clouds",
                            "description": "阴,多云",
                            "icon": "04d"
                        }
                    ],
                    "speed": 6.45,
                    "deg": 195,
                    "clouds": 88,
                    "snow": 0,
                    "rain": 0
                },
                {
                    "dt": 1431748800,
                    "temp": {
                        "day": 300.49,
                        "min": 297.93,
                        "max": 300.49,
                        "night": 297.93,
                        "eve": 298.72,
                        "morn": 299.68
                    },
                    "pressure": 1009.01,
                    "humidity": 0,
                    "weather": [
                        {
                            "id": 503,
                            "main": "Rain",
                            "description": "大雨",
                            "icon": "10d"
                        }
                    ],
                    "speed": 4.85,
                    "deg": 190,
                    "clouds": 21,
                    "snow": 0,
                    "rain": 52.44
                }
            ],
            "Unit": "C",
            "Lang": "ZH_CN"
}

The temperature is a little strange. Should it be divided by 10?

I change the unit to F to make another request, but the response is exactly the same as above. It seems that the unit not works.

I'm on my phone and not near a computer but from what I can tell this might be an overarching bug you've found. I can verify and fix in a few hours. You're more than welcome to patch, test, and submit a pull request if you'd like.

fix in #21.