canva-render/scripts/gen_meta.py

63 lines
2.1 KiB
Python
Raw Permalink Normal View History

2023-12-19 06:39:13 +00:00
import json
import cv2
import pprint
import os.path as osp
from cdf_parser import CdfParser
print("""
<html>
<head>
<style>
.row {
display: flex;
flex-direction: row;
# flex-wrap: wrap;
justify-content: start;
align-items: center;
overflow-x: auto;
margin-bottom: 16px;
align-items: start;
}
.column {
flex: 25%;
padding: 0 1px;
}
</style>
</head>
<body>
""")
path = "https://internblob.blob.core.windows.net/v-lixinyang/canva-render-11.30/{}?sp=racwdli&st=2023-09-17T15:37:58Z&se=2023-12-31T23:37:58Z&spr=https&sv=2022-11-02&sr=c&sig=u%2FPbZ4fNttAPeLj0NEEpX0eIgFcjhot%2Bmy3iGd%2BCmxk%3D"
with open("cdfs.json", "r") as f:
for line in f:
cdf = json.loads(line)
id = cdf['rendered_folder']
cdf_parser = CdfParser(cdf['content'], id)
elements = cdf_parser.get_elements()
print('<div class="row">')
elements = [e for e in elements[::-1]]
for index, element in enumerate(elements):
name = 'full' if index == 0 else f"({index - 1})"
element_text = json.dumps(element, indent=2).replace("\n", "<br/>").replace(" ", "&nbsp;"*2)
print(f"""
<div class="column">
<img src="{path.format(id + f"-{name}.png")}" alt="image" style="width: 300px;">
<br/>
<img src="{path.format(id + f"-({index})-mask.png")}" alt="image" style="width: 300px;">
<p style="word-wrap: break-word; max-height: 300px; max-width: 300px; overflow: auto;"> {element_text} </p>
</div>
""")
print(f"""
<div class="column">
<img src="{path.format(id + f"-({len(elements) - 1}).png")}" alt="image" style="width: 300px;">
<br/>
<p style="word-wrap: break-word; max-height: 300px; overflow: auto;"> Background </p>
</div>
""")
print('</div>')
print("""
</body>
</html>
""")