def __init__(self, teryt_file_name): """ Initiates teryt decoder using csv_file with teryt codes. Arguments: teryt_file_name - name of csv file containing TERYT codes """ csv_file = CsvFile(teryt_file_name, delim=';', quote='"') data = CsvData(csv_file) data.build(rows_type='list') self.codes = {} for row in data.get_rows(): if not self.is_important(row[4]): continue woj, pow, gm = row[1], row[2], row[3] name, type = row[5], row[6] if woj not in self.codes: self.codes[woj] = {'name': name, 'type': type, 'pows': {}} if pow != '00': powiats = self.codes[woj]['pows'] if pow not in powiats: powiats[pow] = {'name': name, 'type': type, 'gms': {}} if gm != '00': gmins = powiats[pow]['gms'] gmins[gm] = {'name': name, 'type': type} csv_file.close()
def __init__(self, file_name): """Initiates decoder using file describing meaning of that figure. Arguments: file_name -- name of file with description of the fourth figure """ csv_file = CsvFile(file_name, delim=';', quote='"') data = CsvData(csv_file) codes = {} for row in data.get_rows(): codes[row[0]] = row[1]
def __init__(self, file_name): """ Initiates jst codes decoder using csv_file with jst codes. Omitts lines that does not describe jst. Arguments: file_name - name of csv file containing jst codes """ csv_file = CsvFile(file_name, delim=';', quote='"', enc='cp1250') data = CsvData(csv_file) data.build(rows_type='list') self.codes = {} for row in data.get_rows(): type = row[4] if type != 'z' and type != 'Z': continue code = row[9] name = row[0] self.codes[code] = name