Kaynağa Gözat

convert panda element to string (img)

tomoya 1 yıl önce
ebeveyn
işleme
44af1a2203
1 değiştirilmiş dosya ile 7 ekleme ve 1 silme
  1. 7 1
      backend/app/app/aianchor/utils2.py

+ 7 - 1
backend/app/app/aianchor/utils2.py

@@ -4,6 +4,7 @@ from pathlib import Path
 import zipfile
 from io import BytesIO
 from chardet.universaldetector import UniversalDetector
+import pandas as pd
 try:
   from app.aianchor.config import *
 except ImportError:
@@ -14,6 +15,10 @@ DEFAULT_ENCODING = "utf-8"
 class VideoMakerError(Exception):
   pass
 
+def json2table(filename: str):
+  table = pd.read_json(filename)
+  print(table)
+  
 def guess_codec(filenames: list) -> str:
   codec_detector = UniversalDetector()
   for filename in filenames:
@@ -51,6 +56,7 @@ def check_zip(zip_filepath:str):
       # excel 裡的圖檔跟zip裡的檔案要一致
       if not table.loc[i, ['素材']].isna().item():
         img =  table.loc[i, ['素材']].item()
+        img = str(img)
         img_files = [x.strip() for x in img.split(',')]
         for img in img_files:
           if Path(img).suffix:
@@ -133,7 +139,7 @@ def check_and_extract_zip(zip_filepath:str, working_dirpath:str):
           elif len(target_filenames) > 1:
             raise VideoMakerError(f'too many same name img files as {img} in zip')
           
-          save_filepath = working_dir_Path / input_dir / true_filenames[target_filenames[0][1]][0]
+          save_filepath = working_dir_Path / input_dir / img_dir / true_filenames[target_filenames[0][1]][0]
           if not save_filepath.exists():
             with open(save_filepath, 'wb') as output_file:  # 建立並開啟新檔案
               with zf.open(filenames[target_filenames[0][1]], 'r') as origin_file:  # 開啟原檔案