"""Bundled dashboard: news."""
import json


def register(ctx):
    from dashboard_bundled.feeds import feed_news

    ctx.register_dashboard_tile(
        {
            "id": "news",
            "title": "News",
            "path": "/tile",
            "refresh_seconds": 1800,
            "priority": 7,
        }
    )

    def route_handler(req):
        body = json.dumps(feed_news(), ensure_ascii=False)
        return {
            "status": 200,
            "headers": {"Content-Type": "application/json; charset=utf-8"},
            "body": body,
        }

    ctx.register_route_handler(route_handler)
