gebos_convert.py 725 B

12345678910111213141516171819202122232425262728
  1. import csv
  2. from pathlib import Path
  3. def convert_dir(path):
  4. source_path = Path(path)
  5. target_path = source_path.parent.joinpath('staging')
  6. for source_file in source_path.glob('*.csv'):
  7. print(source_file.name)
  8. target_file = target_path / source_file.name
  9. convert_file(source_file, target_file)
  10. def convert_file(source, target):
  11. with open(source, 'r', encoding='utf-8') as frh:
  12. with open(target, 'w', encoding='latin-1') as fwh:
  13. csv_reader = csv.reader(frh, delimiter=';')
  14. csv_writer = csv.writer(fwh, delimiter='\t')
  15. csv_writer.writerows(csv_reader)
  16. def main():
  17. convert_dir('E:\\GEBOS\\data')
  18. if __name__ == '__main__':
  19. main()