Skip to content

Commit

Permalink
🔨 code refactoring, paving the way for snapshot-* compactibility when…
Browse files Browse the repository at this point in the history
… free time is available
  • Loading branch information
chfw committed Apr 17, 2019
1 parent ec3c372 commit 5936001
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions pyecharts_snapshot/main.py
Expand Up @@ -125,18 +125,10 @@ async def make_a_snapshot(
logger.VERBOSE = verbose
logger.info(MESSAGE_GENERATING)
file_type = output_name.split(".")[-1]
__actual_delay_in_ms = int(delay * 1000)

if file_type == "svg":
snapshot_js = SNAPSHOT_SVG_JS % __actual_delay_in_ms
else:
snapshot_js = SNAPSHOT_JS % (
file_type,
pixel_ratio,
__actual_delay_in_ms,
)

content = await get_echarts(to_file_uri(file_name), snapshot_js)
content = await async_make_snapshot(
file_name, file_type, pixel_ratio, delay
)

if file_type in [SVG_FORMAT, B64_FORMAT]:
save_as_text(content, output_name)
Expand All @@ -160,6 +152,23 @@ async def make_a_snapshot(
logger.info(MESSAGE_FILE_SAVED_AS % output_name)


async def async_make_snapshot(
html_path: str, file_type: str, pixel_ratio: int = 2, delay: int = 2
):
__actual_delay_in_ms = int(delay * 1000)

if file_type == "svg":
snapshot_js = SNAPSHOT_SVG_JS % __actual_delay_in_ms
else:
snapshot_js = SNAPSHOT_JS % (
file_type,
pixel_ratio,
__actual_delay_in_ms,
)

return await get_echarts(to_file_uri(html_path), snapshot_js)


async def get_echarts(url: str, snapshot_js: str):
browser = await launch()
page = await browser.newPage()
Expand Down

0 comments on commit 5936001

Please sign in to comment.