gen_printers.py 706 B

12345678910111213141516171819202122232425
  1. import json
  2. import csv
  3. csv_file = 'printers/printers.csv'
  4. json_file = 'printers/printers.json'
  5. def json_from_csv():
  6. printers = {}
  7. with open(csv_file, 'r', encoding='utf-8') as file:
  8. reader = csv.reader(file)
  9. for row in reader:
  10. number, model, location, ip = row
  11. shortname = 'print' + str(number)
  12. domain = shortname + '.metalab.ifmo.ru'
  13. printers[shortname] = {'Domain': domain, 'Model': model,
  14. 'Location': location, 'IP': ip}
  15. with open(json_file, 'w', encoding='utf-8') as file:
  16. json.dump(printers, file, indent=4, ensure_ascii=False)
  17. if __name__ == '__main__':
  18. json_from_csv()