|
|
|
|
|
""" |
|
|
Script to convert CSV file of translated localities back to JSON format. |
|
|
""" |
|
|
|
|
|
import json |
|
|
import csv |
|
|
import argparse |
|
|
|
|
|
def convert_csv_to_json(csv_file, json_file): |
|
|
"""Convert CSV file to JSON format.""" |
|
|
|
|
|
data = [] |
|
|
with open(csv_file, 'r', encoding='utf-8', newline='') as f: |
|
|
reader = csv.reader(f) |
|
|
|
|
|
next(reader) |
|
|
|
|
|
for row in reader: |
|
|
if len(row) >= 2: |
|
|
data.append({ |
|
|
"hebrew": row[0], |
|
|
"english": row[1] |
|
|
}) |
|
|
|
|
|
|
|
|
with open(json_file, 'w', encoding='utf-8') as f: |
|
|
json.dump(data, f, ensure_ascii=False, indent=2) |
|
|
|
|
|
print(f"Converted {len(data)} entries from {csv_file} to {json_file}") |
|
|
|
|
|
def main(): |
|
|
parser = argparse.ArgumentParser(description='Convert CSV file to JSON format') |
|
|
parser.add_argument('--input', type=str, default='autogenfolder/localities_translated.csv', |
|
|
help='Input CSV file path (default: autogenfolder/localities_translated.csv)') |
|
|
parser.add_argument('--output', type=str, default='autogenfolder/localities_translated.json', |
|
|
help='Output JSON file path (default: autogenfolder/localities_translated.json)') |
|
|
args = parser.parse_args() |
|
|
|
|
|
convert_csv_to_json(args.input, args.output) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|