Spaces:
Sleeping
Sleeping
Update backend/parser.py
Browse files- backend/parser.py +5 -5
backend/parser.py
CHANGED
@@ -116,9 +116,9 @@ def parse_promotion_pdf(pdf_path):
|
|
116 |
docx_path = pathname + ".docx"
|
117 |
|
118 |
with open(pdf_path, 'rb') as f:
|
119 |
-
convert_pdf_to_word(f, os.path.join('tmp', docx_path))
|
120 |
|
121 |
-
tables = extract_tables_from_docx(os.path.join('tmp', docx_path))
|
122 |
tables_result = parse_table_data(tables)
|
123 |
del tables_result[0]
|
124 |
|
@@ -227,18 +227,18 @@ def parse_promotion_excel(excel_path, filename):
|
|
227 |
data = df.to_dict(orient="records")
|
228 |
|
229 |
# Buat folder temp jika belum ada
|
230 |
-
os.makedirs('tmp', exist_ok=True)
|
231 |
|
232 |
# Tambah .json jika belum ada
|
233 |
if not filename.lower().endswith('.json'):
|
234 |
filename += '.json'
|
235 |
|
236 |
# Cegah overwrite file
|
237 |
-
filepath = os.path.join('tmp', filename)
|
238 |
base_name, ext = os.path.splitext(filename)
|
239 |
copy_num = 1
|
240 |
while os.path.exists(filepath):
|
241 |
-
filepath = os.path.join('tmp', f"{base_name} ({copy_num}){ext}")
|
242 |
copy_num += 1
|
243 |
|
244 |
# Simpan file JSON
|
|
|
116 |
docx_path = pathname + ".docx"
|
117 |
|
118 |
with open(pdf_path, 'rb') as f:
|
119 |
+
convert_pdf_to_word(f, os.path.join('/tmp', docx_path))
|
120 |
|
121 |
+
tables = extract_tables_from_docx(os.path.join('/tmp', docx_path))
|
122 |
tables_result = parse_table_data(tables)
|
123 |
del tables_result[0]
|
124 |
|
|
|
227 |
data = df.to_dict(orient="records")
|
228 |
|
229 |
# Buat folder temp jika belum ada
|
230 |
+
os.makedirs('/tmp', exist_ok=True)
|
231 |
|
232 |
# Tambah .json jika belum ada
|
233 |
if not filename.lower().endswith('.json'):
|
234 |
filename += '.json'
|
235 |
|
236 |
# Cegah overwrite file
|
237 |
+
filepath = os.path.join('/tmp', filename)
|
238 |
base_name, ext = os.path.splitext(filename)
|
239 |
copy_num = 1
|
240 |
while os.path.exists(filepath):
|
241 |
+
filepath = os.path.join('/tmp', f"{base_name} ({copy_num}){ext}")
|
242 |
copy_num += 1
|
243 |
|
244 |
# Simpan file JSON
|