enerpi.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:hass_config 作者: azogue 项目源码 文件源码
def _get_remote_svg_tile(hass, host, port, prefix, name, width_tiles, c1, c2):
    """Get remote SVG file."""
    url_tile = URL_TILE_MASK.format(host, port, prefix, name, width_tiles)
    ok, r_svg, status = False, None, -1
    try:
        r_svg = yield from hass.async_add_job(
            partial(requests.get, url_tile, timeout=15))
        status = r_svg.status_code
        ok = r_svg.ok
    except (requests.ReadTimeout, requests.ConnectionError):
        pass
    if ok:
        # yield from asyncio.sleep(0)
        color1 = ', '.join([str(x) for x in c1])
        color2 = ', '.join([str(x) for x in c2])
        mask_bg = ('background-image: radial-gradient('
                   'farthest-corner at 70% 70%, rgba({}), rgba({}));'
                   .format(color1, color2))
        svg_text_sub = RG_TILE_BACKGROUND.sub(
            '{}{}'.format(MASK_SVG_STYLE, mask_bg),
            r_svg.content.decode(), count=1)
        # svg_text_sub = RG_TILE_SIZE.sub(
        #     # 'viewBox="0 0 600 400"',
        #     'viewBox="0 0 300 250"',
        #     svg_text_sub, count=1)
        # LOGGER.warning(svg_text_sub[:300])
        return svg_text_sub.encode()
    LOGGER.info('TILE REQUEST ERROR [code:{}]: {} - {}'
                .format(status, r_svg, url_tile))
    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号