ini2csv.py 1.1 KB

12345678910111213141516171819202122232425
  1. import configparser, csv, re, argparse
  2. parser = argparse.ArgumentParser()
  3. parser.add_argument('-i', '--input', help='input file', required=True)
  4. parser.add_argument('-o', '--output', help='output file', required=True)
  5. args = parser.parse_args()
  6. tiffs = configparser.ConfigParser()
  7. tiffs.read(args.input, 'utf-16')
  8. with open(args.output, 'w') as csvfile:
  9. csvwriter = csv.writer(csvfile, dialect='excel', delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
  10. csvwriter.writerow(['File name','Directory','Compression','Image dimensions','Color depth','Number of unique colors','Current memory size','File date/time'])
  11. for img in tiffs.sections():
  12. csvwriter.writerow([
  13. tiffs[img]['File name'],
  14. tiffs[img]['Directory'],
  15. tiffs[img]['Compression'],
  16. re.search('.*(?= Pixels)', tiffs[img]['Image dimensions']).group(0),
  17. re.search('.*(?= \()' , tiffs[img]['Color depth']).group(0),
  18. tiffs[img]['Number of unique colors'],
  19. re.search('.*(?= \()' , tiffs[img]['Current memory size']).group(0),
  20. re.sub(' \/','',tiffs[img]['File date/time'])
  21. ])