Hi.
I want to create a custom components that converts an svg from a URL to a local png file.
Something like this. but i have been trying to get som help from OpenAI, but i am stuck.
is there someone that can help me with this.
the URL i want to convert is this:
https://www.yr.no/nb/innhold/1-36072/meteogram.svg
and i need it to be called as a service.
import requests
import io
import cairosvg
import os
from homeassistant.helpers.aiohttp_client import async_get_clientsession
async def convert_svg_to_png(svg_url, output_dir):
session = async_get_clientsession()
try:
response = await session.get(svg_url)
if response.status == 200:
svg_data = await response.read()
png_data = cairosvg.svg2png(bytestring=svg_data)
# Save the PNG file to the specified directory
png_file_path = os.path.join(output_dir, 'meteogram.png')
with open(png_file_path, 'wb') as png_file:
png_file.write(png_data)
return png_file_path
else:
return None
except Exception as e:
return None