Files
yealink2csv/main.py
fabrizio.pappolla 3a6564cf2c Primo commit
2023-06-07 20:52:44 +02:00

57 lines
1.7 KiB
Python

#!/usr/bin/python3
import csv
import os
path = '/srv/tftp/'
header_cfg = """#!version:1.0.0.1
#Tasti rapidi del tastierino esterno
account.1.sip_server.1.address = 192.168.1.7"""
try:
os.chdir(path)
print("Current working directory: {0}".format(os.getcwd()))
except FileNotFoundError:
print("Directory: {0} does not exist".format(path))
except NotADirectoryError:
print("{0} is not a directory".format(path))
except PermissionError:
print("You do not have permissions to change to {0}".format(path))
def main(ofile):
with open(ofile, newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
line_count = 0
to_write = header_cfg
for row in spamreader:
if line_count == 0:
# trova la posizione dei campi che ci interessano
idx_ext = row.index('extension')
idx_name = row.index('name')
else:
if 'idx_ext' not in locals() or 'idx_name' not in locals():
with open("error.txt", "w") as f:
f.write("Errore: file csv senza i campi 'extension' e/o 'name'")
to_write = "\n".join([to_write, print_ext(line_count, row[idx_ext], row[idx_name])])
line_count += 1
print(to_write)
def print_ext(n, n_ext, lbl_ext):
spamrow = f"""expansion_module.1.key.{n}.extension =
expansion_module.1.key.{n}.label = {n_ext}
expansion_module.1.key.{n}.type = 16
expansion_module.1.key.{n}.value = {lbl_ext}"""
return spamrow
def print_hotkeys():
exit
if __name__ == '__main__':
ofile: str = 'tastierino_esterno.csv'
try:
main(ofile)
except FileNotFoundError:
print("File non trovato")