Skip to content

Commit

Permalink
Merge pull request hildogjr#430 from daglem/improved_datasheet_url_va…
Browse files Browse the repository at this point in the history
…lidation

Improved validation of datasheet URLs
  • Loading branch information
hildogjr authored Jan 7, 2021
2 parents 1ca7ac9 + b5be968 commit f98a646
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 2 additions & 4 deletions kicost/spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import xlsxwriter # XLSX file interpreter.
from xlsxwriter.utility import xl_rowcol_to_cell, xl_range, xl_range_abs
from babel import numbers # For currency presentation.
from validators import url as validate_url # URL validator.

# KiCost libraries.
from . import __version__ # Version control by @xesscorp and collaborator.
Expand All @@ -56,9 +57,6 @@

WORKBOOK = None

# Regular expression to the link for one datasheet.
DATASHEET_LINK_REGEX = re.compile('^(http(s)?:\/\/)?(www.)?[0-9a-z\.]+\/[0-9a-z\.\/\%\-\_]+(.pdf)?$', re.IGNORECASE)

# Extra information characteristics of the components gotten in the page that will be displayed as comment in the 'cat#' column.
EXTRA_INFO_DISPLAY = ['value', 'tolerance', 'footprint', 'power', 'current', 'voltage', 'frequency', 'temp_coeff', 'manf', 'size']

Expand Down Expand Up @@ -528,7 +526,7 @@ def get_ref_key(part):
except:
cell_format = wrk_formats['part_format']
pass
if link and re.match(DATASHEET_LINK_REGEX, link):
if link and validate_url(link):
# Just put the link if is a valid format.
wks.write_url(row, start_col + columns['manf#']['col'],
link, string=string, cell_format=cell_format)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def run(self):
'requests >= 2.18.4', # Scrape, API and web modules.
'CurrencyConverter >= 0.13', # Used to convert price to a not available currency in one distributor.
'babel >= 2.6', # For currency format by the language in the spreadsheet.
'validators >= 0.18.2', # For validation of datasheet URLs in the spreadsheet.
# 'wxPython >= 4.0', # Graphical package/library needed to user guide.
]

Expand Down

0 comments on commit f98a646

Please sign in to comment.