Contrib reference¶
Commonly used helper functions, to support in the setup of specific transformations
contrib.read¶
read_map_from_csv
¶
-
data_migrator.contrib.read.
read_map_from_csv
(key=0, value=1, f=<open file '<stdin>', mode 'r'>, delimiter='\t', header=True, as_list=False, unique=False)¶ Generates a map from a csv and adds some validation and list parsing. A function that returns a map for MappingField to use as input in its MappingField.data_map.
>>> from data_migrator.contrib.read import read_map_from_csv >>> table_map = read_map_from_csv(f=open('table.csv'), delimiter=';', key='id', value='name') >>> len(table_map) 10
Note that by default it is expected to have headers in the csv.
Parameters: - f – Filehandle to read the csv from into the map
- delimiter – Option to select another delimiter, other than \t
- key – Name or position of the Key, if
header
is false, the ordinal position is expected (default first) - value – Name or position of the Value, if
header
is false, the ordinal position is expected (default second) - as_list (boolean) – If
True
, data-migrator will treat add all values forkey
as a list. Default isFalse
. - unique (boolean) – If
True
, data-migrator will treat add all non unique values forkey
as a violation and raise aDataException
. Default isFalse
. - header (boolean) – If
True
, data-migrator will treat row as a header column. Default isTrue
Returns: a key, value map from the csv
Return type: map
contrib.dutch¶
clean_phone
¶
-
data_migrator.contrib.dutch.
clean_phone
(v)¶ Cleans phone numbers to dutch clean format
clean_phone clean phone numbers, replaces all characters and spaces adds dutch country code (+31) if no country code is provide
>>> [clean_phone(x) for x in ['00 31 6 - 20 20 20 20','06 20 20 20 20','020 -123 345 6','+440.203.020.23','+440a203a020a23'] ['+31620202020','+31620202020','+31201233456','+4402030203','+4402030203']
Parameters: v (str) – value to clean Returns: cleaned phone number Return type: str