|
@@ -49,7 +49,7 @@ class Mover:
|
|
|
self.source_sheet = source_sheet
|
|
|
self.destination_file_path = destination_file_path
|
|
|
self.destination_sheet = destination_sheet
|
|
|
- self.lines = lines
|
|
|
+ self.lines = self.process_lines(lines)
|
|
|
|
|
|
def move(self, filters={}, add_missing_columns=False):
|
|
|
"""
|
|
@@ -71,8 +71,11 @@ class Mover:
|
|
|
# again opening destination file as it is updated with the source file columns
|
|
|
destination = self.read_xlsx(self.destination_file_path, self.destination_sheet)
|
|
|
|
|
|
- end = self.lines or source.nrows # if number of rows to be considered from source is not predefined the take all
|
|
|
- new_data = [source.row(row) for row in range(1, end)] # create a new list of all data and remove the filtered data
|
|
|
+ end = self.lines # if number of rows to be considered from source is not predefined the take all
|
|
|
+ if not end:
|
|
|
+ for i in range(source.nrows):
|
|
|
+ end.append(i)
|
|
|
+ new_data = [source.row(row) for row in end] # create a new list of all data and remove the filtered data
|
|
|
remove_data = [] # rows not matching filter are stored here which is used later to remove data from new_data
|
|
|
for filter in filters: # iterate through the dictionary of filter and
|
|
|
ind = [x.value for x in source.row(0)].index(filter) # getting index of filter header then use the same index to check data
|
|
@@ -116,6 +119,25 @@ class Mover:
|
|
|
destination_wb.write(1, col, headers)
|
|
|
destination_wb.save()
|
|
|
|
|
|
+ def process_lines(self, lines):
|
|
|
+ line_lis = []
|
|
|
+ lis = [x.strip() for x in lines.split(',')]
|
|
|
+ for l in lis:
|
|
|
+ if "-" in l:
|
|
|
+ start = int(l.split("-")[0].strip())
|
|
|
+ end = int(l.split("-")[1].strip())
|
|
|
+ for i in range(int(start), int(end)+1):
|
|
|
+ if i not in line_lis:
|
|
|
+ line_lis.append(i)
|
|
|
+ elif l.strip().isnumeric():
|
|
|
+ i = int(l.strip())
|
|
|
+ if i not in line_lis:
|
|
|
+ line_lis.append(i)
|
|
|
+ else:
|
|
|
+ raise BaseException('Lines structure is wrong. For multiple values "," is used & for range "-" is used'\
|
|
|
+ 'please verify it again!')
|
|
|
+ return line_lis
|
|
|
+
|
|
|
|
|
|
def parse_json(path):
|
|
|
"""
|