Coder Social home page Coder Social logo

vigilancemeteo's Introduction

Vigilance Météo

Build Status codecov PyPI version License: MIT

Vigilance Météo provides a python API to fetch weather alerts in France or Andorre from Météo France (http://vigilance.meteofrance.com) website.

Classes descritpion

VigilanceMeteoFranceProxy class manages the communication with the source website. The algorithm request a cheksum tiny file to download and update the XML source only when needed.

DepartmentWeatherAlert class allows to fetch all weather alerts for a french department or Andorre. Each DepartmenWeatherAlert instance can have its own proxy, but you should use only one proxy for all DepartmenWeatherAlert instances in your program to avoid too much HTTP request on source website.

Public attributes from DepartmentWeatherAlert class

  • department_color: return the overall criticity color for the department
  • additional_info_URL: return the URL to access more information about department weather alerts from the MétéoFrance website
  • bulletin_date: return the latest bulletin update date & time with timezone
  • department: get or set the department number corresponding to the area watched
  • alerts_list: return the list of all alert types
  • proxy: return the client (a VigilanceMeteoFranceProxy instance) used by the object

Public methods from DepartmentWeatherAlert class

  • update_department_status(): update alerts list by feching latest info from MétéoFrance forcast.
  • summary_message(format): return a string with textual synthesis of the active alerts in department. According to value of 'format' parameter, the string return change: 'text' (default) or 'html'

Public attributes from VigilanceMeteoFranceProxy class

  • xml_tree = XML representation of the weather alert bulletin
  • bulletin_date = Date of the bulletin (with timezone)
  • checksum = Checksum of the weather alert bulletin
  • status = current status of the proxy (possible value in constant.py)

Public Methods from VigilanceMeteoFranceProxyclass

  • update_date(): Check if new information are available and download them if any.
  • get_alert_list(department): of a given department return the list of the alerts.

Examples

>>>import vigilancemeteo

>>>zone = vigilancemeteo.DepartmentWeatherAlert('92')

>>>zone.department_color
'Jaune'

>>>zone.additional_info_URL
'http://vigilance.meteofrance.com/Bulletin_sans.html?a=dept75&b=1&c='

>>>zone.summary_message('text')
'Alerte météo Jaune en cours :\n - Vent violent: Jaune'

Installation

You can use the official release using the pyPi package. Install it with the command: pip install vigilancemeteo

Contribute

If you want to contribute to the development:

  • Start by cloning this repository.
  • Setup a virtual environment
  • Install the python package in edition mode: pip install -e .
  • Create a branch for your feature
  • Test your change using tox
  • Send a PR when ready.

References

Thank you to Lunarok to show an implementation example in PHP for Jeedom. Lot of inspiration for the first python implementation.

Since release 3.0.0, the python implementation use the the recommendation made by Météo France on www.data.gouv.fr.

License

This software is under the MIT License.

vigilancemeteo's People

Contributors

imbuzi avatar oncleben31 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vigilancemeteo's Issues

Pas de retour de vigilance

Depuis un certain temps (jours/semaines désolé pour la précision) j'ai aucun retour d'alerte:

>>> zone = vigilancemeteo.DepartmentWeatherAlert("15")
>>> print(zone.summary_message('text'))
Aucune alerte météo en cours.

Devrait être jaune (orage) ici.

use UTC timestamp for `date_mise_a_jour` property

Currently date_mise_a_jour return a datetime object using date and hour from XML source.
The date is in Paris time Zone implicitly.

date_mise_a_jour should return an object allowing to now when the weather alert bulletin have been emitted whatever is the user time zone.

Error to be catch when XML source unavailable

Update for sensor.vigilance_meteo fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/sensor/alertemeteo.py", line 99, in update
    self._watchedDepartment.miseAJourEtat()
  File "/config/deps/lib/python3.6/site-packages/vigilancemeteo/vigilance.py", line 107, in miseAJourEtat
    tree = etree.parse(ZoneAlerte.URL_VIGILANCE_METEO)
  File "src/lxml/etree.pyx", line 3424, in lxml.etree.parse
  File "src/lxml/parser.pxi", line 1840, in lxml.etree._parseDocument
  File "src/lxml/parser.pxi", line 1866, in lxml.etree._parseDocumentFromURL
  File "src/lxml/parser.pxi", line 1770, in lxml.etree._parseDocFromFile
  File "src/lxml/parser.pxi", line 1163, in lxml.etree._BaseParser._parseDocFromFile
  File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 638, in lxml.etree._raiseParseError
OSError: Error reading file 'http://vigilance.meteofrance.com/data/NXFR33_LFPW_.xml': failed to load external entity "http://vigilance.meteofrance.com/data/NXFR33_LFPW_.xml"

Improve way to manage when HTTP request fail

When the HTTP request failed, currently date_mise_a_jour is set to None, synthese_couleurset to Inconnue and liste_alertes is empty.

The issue is for all the alert type it's difficult to know if it Green or Unknown.

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.