mirror of
https://github.com/c0de-archive/Odoo-Contact-Import.git
synced 2024-12-22 17:12:41 +00:00
Fix file open, write first_row, use UNIX newlines
Small fixes to get this script working the checking logic in find_index is broken and has been disabled for now
This commit is contained in:
parent
2e5e77ce53
commit
358a7d7da7
13
main.py
13
main.py
@ -36,9 +36,9 @@ config = {
|
|||||||
|
|
||||||
# Find the index number of a column in a row and return that
|
# Find the index number of a column in a row and return that
|
||||||
def find_index(row=None, col=None):
|
def find_index(row=None, col=None):
|
||||||
if ((row == None) | (col == None)) | ((type(row) != type(str)) | (type(col) != type(str))):
|
# if ((row == None) | (col == None)) | ((type(row) != type(str)) | (type(col) != type(str))):
|
||||||
raise ValueError('find_index requires both row and col to be set to strings')
|
# raise ValueError('find_index requires both row and col to be set to strings')
|
||||||
exit(1)
|
# exit(1)
|
||||||
|
|
||||||
index = None
|
index = None
|
||||||
for i,j in enumerate(row):
|
for i,j in enumerate(row):
|
||||||
@ -68,18 +68,19 @@ with open(config['partner_path'], 'r') as partner_csv:
|
|||||||
reader = None
|
reader = None
|
||||||
|
|
||||||
# Open both the import_csv and temp_csv files
|
# Open both the import_csv and temp_csv files
|
||||||
with open(config['import_path'], 'r') as import_csv, open(config['temp_path'], 'w') as temp_csv:
|
with open(config['import_path']+'.orig', 'r') as import_csv, open(config['temp_path'], 'w') as temp_csv:
|
||||||
reader = csv.reader(import_csv)
|
reader = csv.reader(import_csv)
|
||||||
writer = csv.writer(temp_csv)
|
writer = csv.writer(temp_csv, lineterminator='\n')
|
||||||
|
|
||||||
first_row = next(reader)
|
first_row = next(reader)
|
||||||
if config['column_to_change'] not in first_row:
|
if config['column_to_change'] not in first_row:
|
||||||
raise IndexError('\'{}\' is not defined in your import_path csv file').format(config['column_to_change'])
|
raise IndexError(config['column_to_change']+' is not defined in your import_path csv file')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
col = find_index(first_row, config['column_to_change'])
|
col = find_index(first_row, config['column_to_change'])
|
||||||
|
|
||||||
if col != None:
|
if col != None:
|
||||||
|
writer.writerow(first_row)
|
||||||
for lines in reader:
|
for lines in reader:
|
||||||
# Taken from http://stackoverflow.com/a/2400577/5727514 and modified to support what I need
|
# Taken from http://stackoverflow.com/a/2400577/5727514 and modified to support what I need
|
||||||
pattern = re.compile('|'.join(partner_ids.keys()))
|
pattern = re.compile('|'.join(partner_ids.keys()))
|
||||||
|
Loading…
Reference in New Issue
Block a user