|
|
@ -144,6 +144,7 @@ class import_xlsx_wachete(Importer):
|
|
|
|
flash,
|
|
|
|
flash,
|
|
|
|
datastore,
|
|
|
|
datastore,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
good = 0
|
|
|
|
good = 0
|
|
|
|
now = time.time()
|
|
|
|
now = time.time()
|
|
|
|
self.new_uuids = []
|
|
|
|
self.new_uuids = []
|
|
|
@ -157,25 +158,24 @@ class import_xlsx_wachete(Importer):
|
|
|
|
flash("Unable to read export XLSX file, something wrong with the file?", 'error')
|
|
|
|
flash("Unable to read export XLSX file, something wrong with the file?", 'error')
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
sheet_obj = wb.active
|
|
|
|
for row in wb.active.iter_rows(min_row=2):
|
|
|
|
|
|
|
|
extras = {}
|
|
|
|
i = 1
|
|
|
|
|
|
|
|
row = 2
|
|
|
|
|
|
|
|
while sheet_obj.cell(row=row, column=1).value:
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
data = {}
|
|
|
|
while sheet_obj.cell(row=row, column=i).value:
|
|
|
|
for cell in row:
|
|
|
|
column_title = sheet_obj.cell(row=1, column=i).value.strip().lower()
|
|
|
|
column_title = wb.active.cell(row=1, column=cell.column).value.strip().lower()
|
|
|
|
column_row_value = sheet_obj.cell(row=row, column=i).value
|
|
|
|
data[column_title] = cell.value
|
|
|
|
data[column_title] = column_row_value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
# Forced switch to webdriver/playwright/etc
|
|
|
|
|
|
|
|
dynamic_wachet = str(data.get('dynamic wachet')).strip().lower() # Convert bool to str to cover all cases
|
|
|
|
|
|
|
|
# libreoffice and others can have it as =FALSE() =TRUE(), or bool(true)
|
|
|
|
|
|
|
|
if 'true' in dynamic_wachet or dynamic_wachet == '1':
|
|
|
|
|
|
|
|
extras['fetch_backend'] = 'html_webdriver'
|
|
|
|
|
|
|
|
|
|
|
|
extras = {}
|
|
|
|
|
|
|
|
if data.get('xpath'):
|
|
|
|
if data.get('xpath'):
|
|
|
|
#@todo split by || ?
|
|
|
|
#@todo split by || ?
|
|
|
|
extras['include_filters'] = [data.get('xpath')]
|
|
|
|
extras['include_filters'] = [data.get('xpath')]
|
|
|
|
if data.get('name'):
|
|
|
|
if data.get('name'):
|
|
|
|
extras['title'] = [data.get('name').strip()]
|
|
|
|
extras['title'] = data.get('name').strip()
|
|
|
|
if data.get('interval (min)'):
|
|
|
|
if data.get('interval (min)'):
|
|
|
|
minutes = int(data.get('interval (min)'))
|
|
|
|
minutes = int(data.get('interval (min)'))
|
|
|
|
hours, minutes = divmod(minutes, 60)
|
|
|
|
hours, minutes = divmod(minutes, 60)
|
|
|
@ -183,7 +183,6 @@ class import_xlsx_wachete(Importer):
|
|
|
|
weeks, days = divmod(days, 7)
|
|
|
|
weeks, days = divmod(days, 7)
|
|
|
|
extras['time_between_check'] = {'weeks': weeks, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': 0}
|
|
|
|
extras['time_between_check'] = {'weeks': weeks, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': 0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# At minimum a URL is required.
|
|
|
|
# At minimum a URL is required.
|
|
|
|
if data.get('url'):
|
|
|
|
if data.get('url'):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -202,10 +201,6 @@ class import_xlsx_wachete(Importer):
|
|
|
|
self.new_uuids.append(new_uuid)
|
|
|
|
self.new_uuids.append(new_uuid)
|
|
|
|
good += 1
|
|
|
|
good += 1
|
|
|
|
|
|
|
|
|
|
|
|
row += 1
|
|
|
|
|
|
|
|
i = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flash(
|
|
|
|
flash(
|
|
|
|
"{} imported from Wachete .xlsx in {:.2f}s".format(len(self.new_uuids), time.time() - now))
|
|
|
|
"{} imported from Wachete .xlsx in {:.2f}s".format(len(self.new_uuids), time.time() - now))
|
|
|
|
|
|
|
|
|
|
|
@ -216,6 +211,7 @@ class import_xlsx_custom(Importer):
|
|
|
|
flash,
|
|
|
|
flash,
|
|
|
|
datastore,
|
|
|
|
datastore,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
good = 0
|
|
|
|
good = 0
|
|
|
|
now = time.time()
|
|
|
|
now = time.time()
|
|
|
|
self.new_uuids = []
|
|
|
|
self.new_uuids = []
|
|
|
@ -231,17 +227,25 @@ class import_xlsx_custom(Importer):
|
|
|
|
|
|
|
|
|
|
|
|
# @todo cehck atleast 2 rows, same in other method
|
|
|
|
# @todo cehck atleast 2 rows, same in other method
|
|
|
|
|
|
|
|
|
|
|
|
sheet_obj = wb.active
|
|
|
|
|
|
|
|
from .forms import validate_url
|
|
|
|
from .forms import validate_url
|
|
|
|
row = 2
|
|
|
|
|
|
|
|
while sheet_obj.cell(row=row, column=1).value:
|
|
|
|
for row in wb.active.iter_rows():
|
|
|
|
url = None
|
|
|
|
url = None
|
|
|
|
tags = None
|
|
|
|
tags = None
|
|
|
|
extras = {}
|
|
|
|
extras = {}
|
|
|
|
for col_i, cell_map in self.import_profile.items():
|
|
|
|
|
|
|
|
cell_val = sheet_obj.cell(row=row, column=col_i).value
|
|
|
|
for cell in row:
|
|
|
|
|
|
|
|
if not self.import_profile.get(cell.col_idx):
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not cell.value:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cell_map = self.import_profile.get(cell.col_idx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cell_val = str(cell.value).strip() # could be bool
|
|
|
|
|
|
|
|
|
|
|
|
if cell_map == 'url':
|
|
|
|
if cell_map == 'url':
|
|
|
|
url = cell_val.strip()
|
|
|
|
url = cell.value.strip()
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
validate_url(url)
|
|
|
|
validate_url(url)
|
|
|
|
except ValidationError as e:
|
|
|
|
except ValidationError as e:
|
|
|
@ -249,19 +253,18 @@ class import_xlsx_custom(Importer):
|
|
|
|
# Don't bother processing anything else on this row
|
|
|
|
# Don't bother processing anything else on this row
|
|
|
|
url = None
|
|
|
|
url = None
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
elif cell_map == 'tag':
|
|
|
|
elif cell_map == 'tag':
|
|
|
|
tags = cell_val.strip()
|
|
|
|
tags = cell.value.strip()
|
|
|
|
elif cell_map == 'include_filters':
|
|
|
|
elif cell_map == 'include_filters':
|
|
|
|
# @todo validate?
|
|
|
|
# @todo validate?
|
|
|
|
extras['include_filters'] = [cell_val.strip()]
|
|
|
|
extras['include_filters'] = [cell.value.strip()]
|
|
|
|
elif cell_map == 'interval_minutes':
|
|
|
|
elif cell_map == 'interval_minutes':
|
|
|
|
hours, minutes = divmod(int(cell_val), 60)
|
|
|
|
hours, minutes = divmod(int(cell_val), 60)
|
|
|
|
days, hours = divmod(hours, 24)
|
|
|
|
days, hours = divmod(hours, 24)
|
|
|
|
weeks, days = divmod(days, 7)
|
|
|
|
weeks, days = divmod(days, 7)
|
|
|
|
extras['time_between_check'] = {'weeks': weeks, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': 0}
|
|
|
|
extras['time_between_check'] = {'weeks': weeks, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': 0}
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
extras[cell_map] = cell_val.strip()
|
|
|
|
extras[cell_map] = cell_val
|
|
|
|
|
|
|
|
|
|
|
|
# At minimum a URL is required.
|
|
|
|
# At minimum a URL is required.
|
|
|
|
if url:
|
|
|
|
if url:
|
|
|
@ -274,7 +277,5 @@ class import_xlsx_custom(Importer):
|
|
|
|
self.new_uuids.append(new_uuid)
|
|
|
|
self.new_uuids.append(new_uuid)
|
|
|
|
good += 1
|
|
|
|
good += 1
|
|
|
|
|
|
|
|
|
|
|
|
row += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flash(
|
|
|
|
flash(
|
|
|
|
"{} imported from custom .xlsx in {:.2f}s".format(len(self.new_uuids), time.time() - now))
|
|
|
|
"{} imported from custom .xlsx in {:.2f}s".format(len(self.new_uuids), time.time() - now))
|
|
|
|