Auto-update: Fri Nov 15 12:35:25 PST 2024
This commit is contained in:
parent
0de289101c
commit
95dab2f08a
1 changed files with 21 additions and 4 deletions
|
@ -13,6 +13,7 @@ from typing import Union, List
|
|||
import folium
|
||||
from folium.plugins import HeatMap, MarkerCluster, Search
|
||||
from folium.plugins import Fullscreen, MiniMap, MousePosition, Geocoder, Draw, MeasureControl
|
||||
from playwright.async_api import async_playwright
|
||||
from zoneinfo import ZoneInfo
|
||||
from dateutil.parser import parse as dateutil_parse
|
||||
from typing import Optional, List, Union
|
||||
|
@ -120,7 +121,6 @@ async def get_last_location() -> Optional[Location]:
|
|||
return None
|
||||
|
||||
|
||||
|
||||
async def generate_and_save_heatmap(
|
||||
start_date: Union[str, int, datetime],
|
||||
end_date: Optional[Union[str, int, datetime]] = None,
|
||||
|
@ -159,7 +159,23 @@ Generate a heatmap for the given date range and save it as a PNG file using Foli
|
|||
if output_path is None:
|
||||
output_path, relative_path = assemble_journal_path(end_date, filename="map", extension=".png", no_timestamp=True)
|
||||
|
||||
m.save(str(output_path))
|
||||
# Save as HTML first
|
||||
temp_html = output_path.with_suffix('.html')
|
||||
m.save(str(temp_html))
|
||||
|
||||
# Use Playwright to convert HTML to PNG
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch()
|
||||
page = await browser.new_page()
|
||||
await page.goto(f'file://{temp_html.absolute()}')
|
||||
# Wait for map to load
|
||||
await page.wait_for_load_state('networkidle')
|
||||
# Take screenshot
|
||||
await page.screenshot(path=str(output_path))
|
||||
await browser.close()
|
||||
|
||||
# Clean up temporary HTML file
|
||||
temp_html.unlink()
|
||||
|
||||
l.info(f"Heatmap saved as PNG: {output_path}")
|
||||
return output_path
|
||||
|
@ -172,6 +188,7 @@ Generate a heatmap for the given date range and save it as a PNG file using Foli
|
|||
l.error(f"Error generating heatmap: {str(e)}")
|
||||
raise
|
||||
|
||||
|
||||
async def generate_map(start_date: datetime, end_date: datetime, max_points: int):
|
||||
locations = await fetch_locations(start_date, end_date)
|
||||
if not locations:
|
||||
|
|
Loading…
Reference in a new issue