|
|
@@ -33,7 +33,13 @@ def read_csv(file_path):
|
|
|
def process_row(row, search_term_index):
|
|
|
# Add translation column after search term
|
|
|
search_term = row[search_term_index]
|
|
|
- translated = translate_sentences([search_term])[0]
|
|
|
+ try:
|
|
|
+ translations = translate_sentences([search_term])
|
|
|
+ translated = translations[0] if translations else "翻译失败"
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Translation error for '{search_term}': {e}")
|
|
|
+ translated = "翻译失败"
|
|
|
+
|
|
|
row.insert(search_term_index + 1, translated)
|
|
|
|
|
|
# Add Amazon search link
|
|
|
@@ -55,7 +61,11 @@ def main(input_file, output_file):
|
|
|
# Process each row (skip header row)
|
|
|
search_term_index = 1 # Search term is in second column
|
|
|
for i, row in enumerate(data[1:], start=1):
|
|
|
- data[i] = process_row(row, search_term_index)
|
|
|
+ try:
|
|
|
+ data[i] = process_row(row, search_term_index)
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error processing row {i}: {e}")
|
|
|
+ continue
|
|
|
|
|
|
# Save processed data
|
|
|
save_csv(data, output_file)
|