Weather wrapper for darksky.net API for Django
Install
-
pip install django_weather_darksky
-
Add django_weather_darksky to INSTALLED_APPS
-
Add to settings.py
# Your API key from https://darksky.net/dev/
DWD_API_KEY = '1234567890'
DWD_LANG = 'ru'
-
python manage.py migrate
-
Add locations via django admin interface
Usage
-
python manage.py load_forecast
-
Add to crontab, for example:
0/30 * * * * /var/www/SITE/venv/bin/python /var/www/SITE/manage.py load_forecast --type currently
0 */3 * * * /var/www/SITE/venv/bin/python /var/www/SITE/manage.py load_forecast --type daily
- Api:
from django_weather_darksky import api
api = DarkSkyAPI(API_KEY, 'ru')
api.set_location(56.0083, 92.8706);
print(api.get_forecast())
print(get_currently().temperature)
api.set_location(55.75, 37.6166);
print(get_daily())
- Django:
from django import template
from django_weather_darksky.models import WeatherForecast
register = template.Library()
@register.inclusion_tag('django_weather_darksky/informer.html', takes_context=True)
def weather_current(context, location):
"""
Current weather informer
"""
data = WeatherForecast.objects.filter(location__slug=location, forecast_type='currently').last()
return {
'data': data
}