Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Python Forecast.io | 410 | 5 years ago | 15 | other | Python | |||||
A thin Python Wrapper for the Dark Sky (formerly forecast.io) weather API | ||||||||||
Clock Weather Card | 98 | 15 days ago | 18 | other | TypeScript | |||||
A Home Assistant Card indicating today's date/time, along with an iOS inspired weather forecast for the next days with animated icons | ||||||||||
Core | 62 | 9 days ago | 15 | other | Lua | |||||
Plugin for Cuberite that implements default commands and some additional functionality | ||||||||||
Worldclockwidget | 49 | 4 years ago | 10 | other | Java | |||||
A world clock and weather widget for Android | ||||||||||
Timeboxed Watchface | 45 | 3 years ago | 14 | mit | C | |||||
A simple, clean and customizable watchface for the Pebble smartwatch | ||||||||||
Hambone | 43 | 3 years ago | mit | Python | ||||||
Raspberry Pi Bot for Ham Radio | ||||||||||
Aw Clock | 41 | 3 months ago | other | TypeScript | ||||||
Astronomy/weather clock | ||||||||||
Forecaswatch2 | 33 | 8 months ago | 16 | gpl-3.0 | C | |||||
Open source revival of the beloved ForecasWatch Pebble watchface | ||||||||||
Temps Lite | 32 | 2 years ago | n,ull | mit | CSS | |||||
A smart, good-looking little app which tries to speak your language the way you are used to. | ||||||||||
Obsidian | 25 | 6 years ago | 8 | other | C | |||||
A usable and elegant analog watchface for the Pebble Time |
This is a wrapper for the Dark Sky (formerly forecast.io) API. It allows you to get the weather for any location, now, in the past, or future.
The Basic Use section covers enough to get you going. I suggest also reading the source if you want to know more about how to use the wrapper or what its doing (it's very simple).
You should use pip to install python-forecastio.
Simple!
Although you don't need to know anything about the Dark Sky API to use this module, their docs are available at https://darksky.net/dev/.
To use the wrapper:
import forecastio
api_key = "YOUR API KEY"
lat = -31.967819
lng = 115.87718
forecast = forecastio.load_forecast(api_key, lat, lng)
...
The load_forecast()
method has a few optional parameters. Providing your API key, a latitude and longitude are the only required parameters.
Use the forecast.DataBlockType()
eg. currently()
, daily()
, hourly()
, minutely()
methods to load the data you are after.
These methods return a DataBlock. Except currently()
which returns a DataPoint.
byHour = forecast.hourly()
print byHour.summary
print byHour.icon
The .data attributes for each DataBlock is a list of DataPoint objects. This is where all the good data is :)
for hourlyData in byHour.data:
print hourlyData.temperature
This makes an API request and returns a Forecast object (see below).
This function allows manual creation of the URL for the Dark Sky API request. This method won't be required often but can be used to take advantage of new or beta features of the API which this wrapper does not support yet. Returns a Forecast object (see below).
forecastio.manual
will not return the forecast object directly, instead it will be passed to the callback function. Make sure it can accept it.The Forecast object, it contains both weather data and the HTTP response from Dark Sky
Contains data about a forecast over time.
Contains data about a forecast at a particular time.
Data points have many attributes, but not all of them are always available. Some commonly used ones are:
For a full list of ForecastioDataPoint attributes and attribute descriptions, take a look at the Dark Sky data point documentation (https://darksky.net/dev/docs/response#data-point)
Requests with a naive datetime (no time zone specified) will correspond to the supplied time in the requesting location. If a timezone aware datetime object is supplied, the supplied time will be in the associated timezone.
Returned times eg the time parameter on the currently DataPoint are always in UTC time even if making a request with a timezone. If you want to manually convert to the locations local time, you can use the offset and timezone attributes of the forecast object.
Typically, would would want to do something like this:
# Amsterdam
lat = 52.370235
lng = 4.903549
current_time = datetime(2015, 2, 27, 6, 0, 0)
forecast = forecastio.load_forecast(api_key, lat, lng, time=current_time)
Be caerful, things can get confusing when doing something like the below. Given that I'm looking up the weather in Amsterdam (+2) while I'm in Perth, Australia (+8).
# Amsterdam
lat = 52.370235
lng = 4.903549
current_time = datetime.datetime.now()
forecast = forecastio.load_forecast(api_key, lat, lng, time=current_time)
The result is actually a request for the weather in the future in Amsterdam (by 6 hours). In addition, since all returned times are in UTC, it will report a time two hours behind the local time in Amsterdam.
If you're doing lots of queries in the past/future in different locations, the best approach is to consistently use UTC time. Keep in mind datetime.datetime.utcnow()
is still a naive datetime. To use proper timezone aware datetime objects you will need to use a library like pytz