Last active
          February 1, 2022 06:05 
        
      - 
      
- 
        Save peace098beat/92846bbe35bd4bfe0c4e8462da2df376 to your computer and use it in GitHub Desktop. 
    [html-build] #matplotlib #python
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import os | |
| import argparse | |
| import glob | |
| def build_html(paths, w=500): | |
| html = """<style> | |
| .d { | |
| width: 500px; | |
| float:left; | |
| } | |
| .c { | |
| width: 450px; | |
| } | |
| </style>""" | |
| for p in paths: | |
| name = os.path.basename(p).split('.')[0] | |
| html+= f""" | |
| <div class="d"> | |
| <a href="https://admin.catlogapp.jp/front/diagnosis/board_log/{name}" target=_brank>{name}</a> | |
| <img class='c' src='{p}'></img> | |
| </div> | |
| \n""" | |
| return html | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--in_dir") | |
| parser.add_argument('--out_dir', default="./") | |
| parser.add_argument('--ext', default="jpg") | |
| parser.add_argument('-r', action='store_true') | |
| args = parser.parse_args() | |
| in_dir = args.in_dir | |
| out_dir = args.out_dir | |
| ext = args.ext | |
| tar_paths = glob.glob(f"{in_dir}/*.{ext}") | |
| assert len(tar_paths)>0, "No files found" | |
| # absolute | |
| tar_paths = [os.path.abspath(p) for p in tar_paths] | |
| tar_paths.sort() | |
| # build html | |
| html = build_html(tar_paths) | |
| # name | |
| out_name = os.path.basename(in_dir) | |
| # save html | |
| save_path = os.path.join(out_dir, f"{out_name}.html") | |
| with open(save_path, "w") as fp: | |
| fp.write(html) | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment