DarkSkyPy - Python 3
A Different Python3 wrapper for the [DarkSky.net](https://www.darksky.net) API.
Rewriting the API to reduce clutter and make obtaining data much more flexible. Based heavily off David Ervideira's forecastiopy.
This API is a work in progress, still very rough not guaranteed to work.
Please use [forecastiopy](https://github.com/dvdme/forecastiopy) (python2.7) or [forecastiopy3](https://github.com/bitpixdigital/forecastiopy3) (python3) if you actually need an API
Powered by [Dark Sky](https://darksky.net/poweredby/)
Install the package:
python setup.py install
Get the coordinates of your location, let's say Lisbon:
>>> Lisbon = [38.7252993, -9.1500364]
Get the current temperature and precipitation probability:
>>> from darkskypy import DarkSky
>>> ds = DarkSky(Lisbon, key=YOUR_APY_KEY)
>>> current_temp = ds.forecast.currently.temperature
>>> print('Temperature:', current_temp)
>>> print('Precipitation Probability:', ds.forecast.currently.precipProbability)
Precipitation Probability: 0.29
* Read Data Points and Data blocks from the [DarkSky.net](https://darksky.net/dev/) API.
Sets up a a hierarchical dictionary object that allows easy access to the currently, minutely, hourly, daily, etc. reports with their nested data. Data can be accessed directly by attributes as a [AttrDict](https://pypi.python.org/pypi/attrdict/2.0.0) object. See Package for more information on how AttrDict works.
Please refer to the API docs [https://darksky.net/dev/docs/forecast](https://darksky.net/dev/docs/forecast) for better understanding of how the Forecast Request is structured and what parameters can be set.
* Actually test this API
* Fix, setup.py
* Improve the docstrings
**Setting API Key**
The required API key can be passed as a kwarg or stored on in your system's environmental variables.
$ export DARKSKY_API_KEY=<api key="">
**Initialize the DarkSky class**
The location should be provided as a list of [latitude,longitude]. Coordinates can be easily obtained from a Geocoding API such as [geocoder](https://github.com/DenisCarriere/geocoder) Optional Parameters are passed as kwargs following the API doc.
g = geocoder.google('Washington, DC')
ds = darkskypy.DarkSky(g.latlng, exclude='minutely,hourly', units='si')
# g.latlng >>> [38.9071923, -77.0368707]
# excludes minutely and hourly data blocks and reports in si units.
**Get Currently weather data for the requested location**
if ds.forecast.currently is True:
for element in ds.forecast.currently:
print(element + ' : ' + str(ds.forecast.currently[element]))
# Or access attributes directly
print('No Currently data')
**Get Daily weather data for the requested location**
The data blocks for Minutely, hourly, and daily data are dictionary sequences that represent each time unit. (i.e. hourly: hours in day, Daily: days in week)
if ds.forecast.daily is True:
# these would relate to the whole Daily block i.e. "the week"
for day in ds.forecast.daily.data:
print('Day summary: '+ day.summary)
# prints the 'summary' for each day
print('No Daily data')
**Alerts and Flags weather data** should work just like Flags and the other ones, but at the time I am writing this, I could not find a location with alerts to test on.
**A note on time**
The API returns time in unix time. Although this is a good computer format, it is not particulary _human-readable_. The datatime module can be used to get a more useful format.
time = datetime.datetime.fromtimestamp(int(currently.time).strftime('%Y-%m-%d %H:%M:%S')
print('unix time:', currently.time)
Output should be like:
unix time: 1448234556
time: 2015-11-22 23:22:36
Please report any issues at [Github](https://github.com/mattbox/DarkSkyPy)
TODO: Brief introduction on what you do with files - including link to relevant help section.