Skip to content

Commit

Permalink
use calamine
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy-Galil committed Aug 15, 2024
1 parent 4e62621 commit bee1a8a
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions djang/importer/services/xsls_ingester.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ class xls_ingester(object):
def __init__(self):
super().__init__()

def get_sheetnames(self, wb):
return wb.sheetnames

def find_sn(self, wb):
sheet_name_array = wb.sheetnames
sheet_name_array = self.get_sheetnames(wb)
for sn in sheet_name_array:
# ignore dynamic pick lists that exists in some of the reports
if sn.startswith("{PL}PickLst"):
Expand Down Expand Up @@ -80,6 +83,13 @@ def put_header_fields(self, reference_objects):
val = datetime.datetime.now()
self.reference_objects = self.put_in_model(
self.reference_objects, field, val)

def getSheet(self, wb, sn):
for sn1 in sn:
if sn1 in wb:
sn2 = sn1
break
return wb[sn2]

def parse_first_tab(self, wb, sn, tab):
# from first tab get report date, company, track name and track code
Expand All @@ -89,31 +99,33 @@ def parse_first_tab(self, wb, sn, tab):
if field["type"] == 'generated':
continue
else:
for row in wb[sn].iter_rows(min_row=1, max_row=4, max_col=4, values_only=False):
for cell in row:
found = False
if cell.value is not None:
if str(cell.value).startswith("{PL}PickLst"):
break
stripped = str(cell.value).replace(
'*', '').replace(":", "").strip()
for field1 in tab["fields"]:
# in some of the reports there are multiple * characters of column titles as pointers to comments
if stripped in field1["column_title"]:
found = True
i = 1
for i in range(1, 4):
val = wb[sn].cell(
row=cell.row, column=cell.column+i).value
if val is not None:
self.reference_objects = self.put_in_model(
self.reference_objects, field1, val)
break
worksheet = self.getSheet(wb, sn)
if worksheet is not None:
for row in worksheet.iter_rows(min_row=1, max_row=4, max_col=4, values_only=False):
for cell in row:
found = False
if cell.value is not None:
if str(cell.value).startswith("{PL}PickLst"):
break
elif field1["type"] == "reference":
self.reference_objects = self.put_in_model(
self.reference_objects, field1, None)
break
stripped = str(cell.value).replace(
'*', '').replace(":", "").strip()
for field1 in tab["fields"]:
# in some of the reports there are multiple * characters of column titles as pointers to comments
if stripped in field1["column_title"]:
found = True
i = 1
for i in range(1, 4):
val = wb[sn2].cell(
row=cell.row, column=cell.column+i).value
if val is not None:
self.reference_objects = self.put_in_model(
self.reference_objects, field1, val)
break
break
elif field1["type"] == "reference":
self.reference_objects = self.put_in_model(
self.reference_objects, field1, None)
break
self.save_first_tab()

return
Expand Down Expand Up @@ -321,6 +333,7 @@ def ingest(self, filename, file_stream):
self.reference_objects.clear()
return True
except ValueError:

#traceback.print_exc()
print("report already exists")
return False
Expand Down

0 comments on commit bee1a8a

Please sign in to comment.