GithubHelp home page GithubHelp logo

jefftriplett / requests-forecast Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 2.0 105 KB

:umbrella: A minimalist Forecast.io API client

Home Page: https://gitlab.com/jeff.triplett/requests-forecast

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

requests-forecast's Introduction

requests-forecast

๐Ÿšง WIP updates

This project "just worked" for half a decade until DarkSky announced they were shuttering their support.

This is a WIP upgrade to switch the API over to https://weathermachine.io

This will break, shift, and will eventually be renamed to support this new library.


For complete docs and API options see: https://weathermachine.io/docs

For complete docs and API options see: https://developer.forecast.io/docs/v2

Requirements

  • Python 3.6+
  • requests

Installation

To install requests-forecast, simply:

$ pip install requests-forecast

Documentation

Quickstart

Creating a client

from requests_forecast import Forecast

forecast = Forecast(apikey='YOUR-API-KEY')

Getting the current conditions

current = forecast.currently()
print(current['temperature'])
58.9

Getting minutely conditions

current = forecast.minutely()
current['summary']
u'Mostly cloudy for the hour.'
current['data'][0].keys()
[u'precipIntensity', u'time']

Getting hourly conditions

current = forecast.hourly()
current['temperature']
59.52
forecast.hourly()['summary']
Mostly cloudy until tomorrow afternoon.
forecast.hourly()['data'][0]['temperature']
59.52

Getting daily conditions

forecast.daily()['summary']
u'Mixed precipitation off-and-on throughout the week; temperatures peaking at 70\xb0 on Sunday.'
forecast.daily()['data'][0]['temperatureMax']
63.85
forecast.daily()['data'][0]['temperatureMin']
35.05

Getting alerts

forecast.alerts()
{
  "expires": 1366898400,
  "uri": "http://alerts.weather.gov/cap/wwacapget.php?x=KS124EFAC89CD0.FreezeWarning.124EFAD6F320KS.TOPNPWTOP.8ab7d76a4db42b9136a1a6849a631097",
  "title": "Freeze Warning for Douglas, KS"
}

Example usage

from requests_forecast import Forecast

forecast = Forecast(apikey='YOUR-API-KEY')
data = forecast.get(latitude=38.9717, longitude=-95.235)

forecast.currently()['temperature']
58.9

data = forecast.get(latitude=38.9717, longitude=-95.235)

forecast.currently()['temperature']
58.9

forecast.currently()['temperature']
36.75

License

New BSD

requests-forecast's People

Contributors

jefftriplett avatar bendavis78 avatar

Stargazers

gregory nicholas avatar Douglas Miranda avatar Audrey M. Roy Greenfeld avatar katy lavallee avatar Flavio Curella avatar Kevin avatar

Watchers

 avatar James Cloos avatar  avatar

requests-forecast's Issues

Exception getting alerts when there are none

When there are no alerts, forecast.get_alerts() should return None (or maybe an empty list).

In [11]: forecast.get_alerts()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/.../.venv/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 forecast.get_alerts()

/Users/.../.venv/lib/python2.7/site-packages/requests_forecast.pyc in get_alerts(self)
     79             #return self.json.alerts
     80             return DataBlock(self.json.alerts, self.timezone)
---> 81         return DataBlock()
     82
     83     def get_currently(self):

/Users/.../.venv/lib/python2.7/site-packages/requests_forecast.pyc in __init__(self, data, timezone)
     12     def __init__(self, data=None, timezone=None):
     13         self.timezone = timezone
---> 14         super(DataBlock, self).__init__(data)
     15         self.data = []
     16

TypeError: 'NoneType' object is not iterable

Obviously this is not critical, as I can catch the TypeError in my own code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.