All Projects → lukaskubis → Darkskylib

lukaskubis / Darkskylib

Licence: mit
Python wrapper for the Dark Sky API

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Darkskylib

Dark Sky Api
PHP Library for the Dark Sky API.
Stars: ✭ 70 (-37.5%)
Mutual labels:  forecast, weather
weather-milliseconds
Experiment to render a forecast as fast as possible
Stars: ✭ 24 (-78.57%)
Mutual labels:  weather, forecast
darksky
Forecast.io API wrapper in Go (Golang)
Stars: ✭ 74 (-33.93%)
Mutual labels:  weather, forecast
Weather
Weather Android App using apixu API https://www.apixu.com
Stars: ✭ 48 (-57.14%)
Mutual labels:  weather, forecast
Darksky
Python API wrapper for the DarkSky (async&sync)
Stars: ✭ 81 (-27.68%)
Mutual labels:  forecast, weather
solar-weather
React Native Weather App w. Realm, Redux, ReasonReact & Forecast.io
Stars: ✭ 13 (-88.39%)
Mutual labels:  weather, forecast
Jupiter
🌞 The Swift Weather Framework
Stars: ✭ 14 (-87.5%)
Mutual labels:  weather, forecast
Forecastr
A simple, asynchronous Objective-C wrapper for the Forecast.io API
Stars: ✭ 143 (+27.68%)
Mutual labels:  forecast, weather
Wego
weather app for the terminal
Stars: ✭ 6,918 (+6076.79%)
Mutual labels:  forecast, weather
Temps
Simple menubar application based on Electron with actual weather information and forecast.
Stars: ✭ 553 (+393.75%)
Mutual labels:  forecast, weather
MMM-forecast-io
Forecast.io Module for MagicMirror
Stars: ✭ 58 (-48.21%)
Mutual labels:  weather, forecast
Weather
A module for obtaining weather information
Stars: ✭ 54 (-51.79%)
Mutual labels:  forecast, weather
mpxday
mpxday是基于mpx开发的天气预报微信小程序
Stars: ✭ 3 (-97.32%)
Mutual labels:  weather, forecast
temps-lite
A smart, good-looking little app which tries to speak your language the way you are used to.
Stars: ✭ 40 (-64.29%)
Mutual labels:  weather, forecast
Good Weather
Open source weather app for Andorid
Stars: ✭ 198 (+76.79%)
Mutual labels:  forecast, weather
File-Maker
Generate data files for Wii Channels that have the latest news, forecast data, etc.
Stars: ✭ 65 (-41.96%)
Mutual labels:  weather, forecast
Getme
CLI utility for everyday tasks. With getme you get weather, forecast, currency rate, upload files, IP address, word definitions, text translations, internet speed, do google searches, get inspirational quotes and get Chuck Norris jokes
Stars: ✭ 118 (+5.36%)
Mutual labels:  forecast, weather
darksky2influxdb
Stores wheather forcecast data from darkskyapi into a influxdb database
Stars: ✭ 21 (-81.25%)
Mutual labels:  weather, forecast
Node Forecastio
A node.js client for Forecast.io API
Stars: ✭ 32 (-71.43%)
Mutual labels:  forecast, weather
Weacast
Weacast demo application
Stars: ✭ 55 (-50.89%)
Mutual labels:  forecast, weather

darkskylib

This library for the Dark Sky API <https://darksky.net/dev/docs>__ provides access to detailed weather information from around the globe.

Quick start

Before you start using this library, you need to get your API key here <https://darksky.net/dev/register>__.

API Calls


Function ``forecast`` handles all request parameters and returns a
``Forecast`` object.

.. code:: python

    >>> from darksky import forecast
    >>> boston = forecast(key, 42.3601, -71.0589)
    >>>

The first 3 positional arguments are identical to the 3 required
parameters for API call. The optional query parameters need to be
provided as keyword arguments.

Using ``time`` argument will get you a **time machine call**.
Using ``timeout`` argument will set default `request timeout <http://docs.python-requests.org/en/master/api/#requests.request>`__ .

.. code:: python

    >>> BOSTON = key, 42.3601, -71.0589
    >>> from datetime import datetime as dt
    >>> t = dt(2013, 5, 6, 12).isoformat()
    >>> boston = forecast(*BOSTON, time=t)
    >>> boston.time
    1367866800

Data Points and Data Blocks

The values as well as DataPoint and DataBlock objects are accessed using instance attributes or dictionary keys. You can access current values directly, without going through currently data point.

.. code:: python

>>> boston['currently']['temperature']
60.72
>>> boston.temperature
60.72

Data blocks are indexable and iterable by their data values.

.. code:: python

>>> len(boston.hourly)
24
>>>
>>> boston.hourly[1].temperature
59.49
>>>
>>> # list temperatures for next 10 hours
... [hour.temperature for hour in boston.hourly[:10]]
[60.83, 59.49, 58.93, 57.95, 56.01, 53.95, 51.21, 49.21, 47.95, 46.31]

Nonexistent attributes will raise AttributeError and dictionary keys KeyError the way you'd expect.

Raw data


To get the raw data dictionary, you can either access it through
instance attributes or navigate to it through dictionary keys, the same
way you would navigate the actual dictionary.

.. code:: python

    >>> boston.hourly[2]
    {'ozone': 290.06, 'temperature': 58.93, 'pressure': 1017.8, 'windBearing': 274, 'dewPoint': 52.58, 'cloudCover': 0.29, 'apparentTemperature': 58.93, 'windSpeed': 7.96, 'summary': 'Partly Cloudy', 'icon': 'partly-cloudy-night', 'humidity': 0.79, 'precipProbability': 0, 'precipIntensity': 0, 'visibility': 8.67, 'time': 1476410400}
    >>>
    >>> boston['hourly']['data'][2]
    {'ozone': 290.06, 'temperature': 58.93, 'pressure': 1017.8, 'windBearing': 274, 'dewPoint': 52.58, 'cloudCover': 0.29, 'apparentTemperature': 58.93, 'windSpeed': 7.96, 'summary': 'Partly Cloudy', 'icon': 'partly-cloudy-night', 'humidity': 0.79, 'precipProbability': 0, 'precipIntensity': 0, 'visibility': 8.67, 'time': 1476410400}

Flags and Alerts

All dashes - in attribute names of Flags objects are replaced by underscores _. This doesn't affect the dictionary keys.

.. code:: python

>>> # instead of 'boston.flags.isd-stations'
... boston.flags.isd_stations
['383340-99999', '383390-99999', '383410-99999', '384620-99999', '384710-99999']
>>>
>>> boston.flags['isd-stations']
['383340-99999', '383390-99999', '383410-99999', '384620-99999', '384710-99999']

Even though Alerts are represented by a list, the data accessibility through instance attributes is preserved for alerts in the list.

.. code:: python

>>> boston.alerts[0].title
'Freeze Watch for Norfolk, MA'

Updating data


Use ``refresh()`` method to update data of a ``Forecast`` object. The
``refresh()`` method takes optional queries (including ``time``, making
it a **Time machine** object) as keyword arguments. Calling
``refresh()`` without any arguments will set all queries to default
values. Use ``timeout`` argument to set the request timeout.

.. code:: python

    >>> boston.refresh()
    >>> (boston.time, boston.temperature, len(boston.hourly))
    (1476403500, 60.72, 49)
    >>>
    >>> boston.refresh(units='si', extend='hourly')
    >>> (boston.time, boston.temperature, len(boston.hourly))
    (1476404205, 15.81, 169)
    >>>
    >>> boston.refresh(units='us')
    >>> (boston.time, boston.temperature, len(boston.hourly))
    (1476404489, 60.57, 49)

For Developers

Response headers are stored in a dictionary under response_headers attribute.

.. code:: python

>>> boston.response_headers['X-response-Time']
'146.035ms'

Example script

.. code:: python

from darksky import forecast
from datetime import date, timedelta

BOSTON = 42.3601, 71.0589

weekday = date.today()
with forecast('API_KEY', *BOSTON) as boston:
    print(boston.daily.summary, end='\n---\n')
    for day in boston.daily:
        day = dict(day = date.strftime(weekday, '%a'),
                   sum = day.summary,
                   tempMin = day.temperatureMin,
                   tempMax = day.temperatureMax
                   )
        print('{day}: {sum} Temp range: {tempMin} - {tempMax}'.format(**day))
        weekday += timedelta(days=1)

Output:

::

Light rain on Friday and Saturday, with temperatures bottoming out at 48°F on Tuesday.
---
Sun: Partly cloudy in the morning. Temp range: 44.86 - 57.26°F
Mon: Mostly cloudy in the morning. Temp range: 44.26 - 55.28°F
Tue: Clear throughout the day. Temp range: 36.85 - 47.9°F
Wed: Partly cloudy starting in the afternoon, continuing until evening. Temp range: 33.23 - 47.93°F
Thu: Light rain overnight. Temp range: 35.75 - 49.71°F
Fri: Light rain in the morning and afternoon. Temp range: 45.47 - 57.11°F
Sat: Drizzle in the morning. Temp range: 43.3 - 62.08°F
Sun: Clear throughout the day. Temp range: 39.81 - 60.84°F

License

The code is available under terms of MIT License <https://raw.githubusercontent.com/lukaskubis/darkskylib/master/LICENSE>__

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].