slavama / django_weather_darksky

Weather wrapper for darksky.net API for Django

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weather wrapper for darksky.net API for Django

Install

  1. pip install django_weather_darksky

  2. Add django_weather_darksky to INSTALLED_APPS

  3. Add to settings.py

# Your API key from https://darksky.net/dev/
DWD_API_KEY = '1234567890'
DWD_LANG = 'ru'
  1. python manage.py migrate

  2. Add locations via django admin interface

Usage

  1. python manage.py load_forecast

  2. 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
  1. 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())
  1. 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
    }

About

Weather wrapper for darksky.net API for Django

License:MIT License


Languages

Language:Python 97.7%Language:HTML 2.3%