platypush/platypush/backend/weather/forecast.py
Fabio Manganiello d83c2c903f - Added support for /dashboard page with customizable widgets under the web server
- Introduced Redis to pass messages between the Flask process and the
main application. It now syncs messages with the bus and connected websockets
- Added support to programmatically modify dashboard widgets through POST request like Dashing
- Added weather forecast plugin
2018-05-04 03:24:35 +02:00

35 lines
1 KiB
Python

import logging
import time
from platypush.backend import Backend
from platypush.context import get_plugin
from platypush.plugins.weather.forecast import WeatherForecastPlugin
from platypush.message.event.weather import NewWeatherConditionEvent
class WeatherForecastBackend(Backend):
def __init__(self, poll_seconds, **kwargs):
super().__init__(**kwargs)
self.poll_seconds = poll_seconds
self.latest_update = {}
def send_message(self, msg):
pass
def run(self):
super().run()
weather = get_plugin('weather.forecast')
logging.info('Initialized weather forecast backend')
while not self.should_stop():
current_weather = weather.get_current_weather().output
del current_weather['time']
if current_weather != self.latest_update:
self.bus.post(NewWeatherConditionEvent(**current_weather))
self.latest_update = current_weather
time.sleep(self.poll_seconds)
# vim:sw=4:ts=4:et: