Skip to main content

This djangocms plugin allows you to add a weather indicator on your pages, using the Dark Sky API (https://darksky.net/dev/docs).

Project description

djangocms-darksky-api

The weather plugin that links djangocms and Dark Sky.

Installation

  1. Install module using pipenv:
pipenv install djangocms-darksky-api
  • Or pip:
pip install djangocms-darksky-api
  1. Add it to your installed apps:
    "djangocms_darksky_api",
  1. Apply migrations
py manage.py migrate djangocms_darksky_api
  1. Include your api key in your settings (get one on darksky website)
DJANGOCMS_DARKSKY_API_SETTINGS = {"api_key": "your key here"}
  • Or load it using an environment var:
import os
DJANGOCMS_DARKSKY_API_SETTINGS = {"api_key": os.getenv("DARKSKY_API_KEY", None)}
  1. Include weather plugin on your pages using djangocms Add dark sky api plugin
  2. That's all folks!

Examples

Raw results

Light template (view & src)

light template raw

Full template (view & src)

full template raw

Error msg (if api.darksky.net is down)

As the darksky api will sometimes suffer downtimes, the plugin can display an error message ("Data is currently unavailable."), embedded in a dataset.

error message code

Examples of rendered views

Light template

light template rendered

Full template:

full template rendered

Miscellaneous

Css

Css classes for the icons (e.g. <div class="darksky-icon darksky-rain"></div>) are of the form darksky-icon darksky-[name].

[name] can be any of the following values (see darksky doc):

  • clear-day
  • clear-night
  • rain
  • snow
  • sleet
  • wind
  • fog
  • cloudy
  • partly-cloudy-day
  • partly-cloudy-night

Units

All values are returned using the International System (°C, km/h, ...) and are hard-coded in templates files.


Language

The language is searched using django.utils.translation.get_language() & django.conf.LANGUAGE_CODE.

Languages supported by the Dark Sky api can be found on their documentation.


Cache

Plugin

The plugin is cached (with the same duration as the json content).

Json

The values are cached for one hour (which avoids hundreds of thousands of queries per day on the darksky api site).

If you want to change the cache duration, add a cache entry in your DJANGOCMS_DARKSKY_API_SETTINGS dict, in your settings.py:

DJANGOCMS_DARKSKY_API_SETTINGS = {
    "api_key": "mysuperapikey",
    "cache": 60 * 60, # one hour
}

Or load it using an environment var:

import os
DJANGOCMS_DARKSKY_API_SETTINGS = {
    "api_key": os.getenv("DARKSKY_API_KEY", None),
    "cache": os.getenv("DARKSKY_CACHE_DURATION", 60 * 60), # return content of DARKSKY_CACHE_DURATION if it exists, or one hour if it doesn't
}

As stated in Django docs; "[The timeout is] the number of seconds the value should be stored in the cache. Passing in None for timeout will cache the value forever. A timeout of 0 won’t cache the value."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangocms-darksky-api-0.0.6.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

djangocms_darksky_api-0.0.6-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file djangocms-darksky-api-0.0.6.tar.gz.

File metadata

  • Download URL: djangocms-darksky-api-0.0.6.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.9

File hashes

Hashes for djangocms-darksky-api-0.0.6.tar.gz
Algorithm Hash digest
SHA256 eb6e369bda482b8500679bae02e41346b9d794a5e23de7691878a6a6fa936abe
MD5 c61cf951248af145a4d87f0400ed3859
BLAKE2b-256 535641645b1466c4d34815e0df0f04d37a7e4b74a11acf4283f8a8c2cc89867d

See more details on using hashes here.

File details

Details for the file djangocms_darksky_api-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: djangocms_darksky_api-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.9

File hashes

Hashes for djangocms_darksky_api-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 344d4e1a61705d01efafbab2611800c5e652766129467939a4e79472faa30baa
MD5 ad3cdcd1fec883e7fb6b80c20d568141
BLAKE2b-256 1fda1e1b0a966a37d5d1b4cf93a25a0d6ae83121c161f714869c286e16e2f037

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page