diff --git a/render/app.py b/render/app.py new file mode 100644 index 0000000..6af3f1b --- /dev/null +++ b/render/app.py @@ -0,0 +1,4 @@ +from render import app + +if __name__ == "__main__": + app.run() \ No newline at end of file diff --git a/render/render.py b/render/render.py new file mode 100644 index 0000000..8ebf3d5 --- /dev/null +++ b/render/render.py @@ -0,0 +1,40 @@ +import asyncio +from pyppeteer import launch +import os +from PIL import Image +from flask import Flask, send_file +import io + +app = Flask(__name__) + +async def render_html_to_png(html_file_name, css_file_name, output_file_name): + browser = await launch() + page = await browser.newPage() + await page.setViewport({'width': 800, 'height': 480}) + + current_dir = os.path.dirname(__file__) + html_file_path = os.path.join(current_dir, html_file_name) + css_file_path = os.path.join(current_dir, css_file_name) + output_file_path = os.path.join(current_dir, output_file_name) + + await page.goto(f'file://{html_file_path}') + await page.addStyleTag({'path': css_file_path}) + + screenshot = await page.screenshot() + image = Image.open(io.BytesIO(screenshot)) + image.save(output_file_path) + + await browser.close() + +@app.route('/weather', methods=['GET']) +def generate_weather_image(): + html_file_path = 'weather.html' + css_file_path = 'styles.css' + output_file_path = 'weather.png' + + asyncio.get_event_loop().run_until_complete(render_html_to_png(html_file_path, css_file_path, output_file_path)) + + return send_file(output_file_path, mimetype='image/png') + +if __name__ == "__main__": + app.run(host='0.0.0.0', port=5233) diff --git a/render/styles.css b/render/styles.css new file mode 100644 index 0000000..55b705e --- /dev/null +++ b/render/styles.css @@ -0,0 +1,98 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; +} + +.weather-container { + width: 700px; + margin: 0 auto; + padding: 20px; + background-color: #fff; + border-radius: 10px; + box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); +} + +h1 { + text-align: center; + color: #333; +} + +.additional-info { + display: flex; + justify-content: space-between; + margin-bottom: 20px; +} + +.info-item { + flex: 0 1 calc(50% - 10px); + padding: 10px; + background-color: #f9f9f9; + border-radius: 5px; +} + +.info-label { + font-size: 14px; + color: #666; +} + +.info-value { + font-size: 16px; + color: #333; +} + +.current-weather { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 20px; +} + +.weather-icon { + width: 100px; + height: 100px; + background-color: #ccc; + border-radius: 50%; +} + +.temperature { + font-size: 24px; + color: #333; +} + +h2 { + margin-top: 20px; + color: #666; +} + +.forecast { + display: flex; + justify-content: space-between; + flex-wrap: wrap; +} + +.forecast-item { + flex-basis: calc(10% - 10px); + text-align: center; + padding: 10px; + background-color: #f9f9f9; + border-radius: 5px; + margin-bottom: 10px; +} + +.forecast-time { + font-size: 14px; + color: #666; +} + +.forecast-icon { + width: 50px; + height: 50px; + background-color: #ccc; + border-radius: 50%; + margin-bottom: 5px; +} + +.forecast-temperature { + font-size: 16px; + color: #333; +} diff --git a/render/weather.html b/render/weather.html new file mode 100644 index 0000000..26c8d02 --- /dev/null +++ b/render/weather.html @@ -0,0 +1,80 @@ + + +
+ + +