seawolf2357 commited on
Commit
82f3557
·
verified ·
1 Parent(s): 59c6ad0

Upload debug_conversion_v2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. debug_conversion_v2.py +41 -0
debug_conversion_v2.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pyhwp.html_converter import HwpToHtmlConverter
2
+ from hwp5.hwp5html import HTMLTransform
3
+ from hwp5.xmlmodel import Hwp5File
4
+ from contextlib import closing
5
+ import os
6
+ import sys
7
+
8
+ def main():
9
+ hwp_file = 'test.hwp'
10
+ output_path = 'test.html'
11
+
12
+ print("Step 1: Init HTMLTransform", flush=True)
13
+ transformer = HTMLTransform()
14
+ output_dir = os.path.dirname(os.path.abspath(output_path))
15
+
16
+ print(f"Step 2: Opening {hwp_file}", flush=True)
17
+ with closing(Hwp5File(hwp_file)) as hwp5file:
18
+ print("Step 3: Creating temp XHWP5", flush=True)
19
+ with transformer.transformed_xhwp5_at_temp(hwp5file) as xhwp5path:
20
+ print(f"Step 4: Temp XHWP5 at {xhwp5path}", flush=True)
21
+
22
+ print("Step 5: Generating HTML...", flush=True)
23
+ with open(output_path, 'wb') as f:
24
+ transformer.transform_xhwp5_to_xhtml(xhwp5path, f)
25
+ print("Step 5: HTML Done", flush=True)
26
+
27
+ print("Step 6: Generating CSS...", flush=True)
28
+ css_path = os.path.join(output_dir, 'styles.css')
29
+ with open(css_path, 'wb') as f:
30
+ transformer.transform_xhwp5_to_css(xhwp5path, f)
31
+ print("Step 6: CSS Done", flush=True)
32
+
33
+ print("Step 7: Extracting BinData...", flush=True)
34
+ bindata_dir = os.path.join(output_dir, 'bindata')
35
+ transformer.extract_bindata_dir(hwp5file, bindata_dir)
36
+ print("Step 7: BinData Done", flush=True)
37
+
38
+ print("All Done", flush=True)
39
+
40
+ if __name__ == "__main__":
41
+ main()