notify-api-412 use black to enforce python coding style

This commit is contained in:
Kenneth Kehl
2023-08-25 09:12:23 -07:00
parent c6eb007386
commit 8c9721d8e2
201 changed files with 31660 additions and 28105 deletions

View File

@@ -6,26 +6,21 @@ import pyexcel
import pyexcel_xlsx
class Spreadsheet():
ALLOWED_FILE_EXTENSIONS = ('csv', 'xlsx', 'xls', 'ods', 'xlsm', 'tsv')
def __init__(self, csv_data=None, rows=None, filename=''):
class Spreadsheet:
ALLOWED_FILE_EXTENSIONS = ("csv", "xlsx", "xls", "ods", "xlsm", "tsv")
def __init__(self, csv_data=None, rows=None, filename=""):
self.filename = filename
if csv_data and rows:
raise TypeError('Spreadsheet must be created from either rows or CSV data')
raise TypeError("Spreadsheet must be created from either rows or CSV data")
self._csv_data = csv_data or ''
self._csv_data = csv_data or ""
self._rows = rows or []
@property
def as_dict(self):
return {
'file_name': self.filename,
'data': self.as_csv_data
}
return {"file_name": self.filename, "data": self.as_csv_data}
@property
def as_csv_data(self):
@@ -43,37 +38,36 @@ class Spreadsheet():
@staticmethod
def get_extension(filename):
return path.splitext(filename)[1].lower().lstrip('.')
return path.splitext(filename)[1].lower().lstrip(".")
@staticmethod
def normalise_newlines(file_content):
return '\r\n'.join(file_content.read().decode('utf-8').splitlines())
return "\r\n".join(file_content.read().decode("utf-8").splitlines())
@classmethod
def from_rows(cls, rows, filename=''):
def from_rows(cls, rows, filename=""):
return cls(rows=rows, filename=filename)
@classmethod
def from_dict(cls, dictionary, filename=''):
def from_dict(cls, dictionary, filename=""):
return cls.from_rows(
zip(
*sorted(dictionary.items(), key=lambda pair: pair[0])
),
zip(*sorted(dictionary.items(), key=lambda pair: pair[0])),
filename=filename,
)
@classmethod
def from_file(cls, file_content, filename=''):
def from_file(cls, file_content, filename=""):
extension = cls.get_extension(filename)
if extension == 'csv':
return cls(csv_data=Spreadsheet.normalise_newlines(file_content), filename=filename)
if extension == "csv":
return cls(
csv_data=Spreadsheet.normalise_newlines(file_content), filename=filename
)
if extension == 'tsv':
file_content = StringIO(
Spreadsheet.normalise_newlines(file_content))
if extension == "tsv":
file_content = StringIO(Spreadsheet.normalise_newlines(file_content))
if extension == 'xlsm':
if extension == "xlsm":
file_data = pyexcel_xlsx.get_data(file_content)
instance = cls.from_rows(
# Get the first sheet from the workbook
@@ -83,10 +77,8 @@ class Spreadsheet():
return instance
instance = cls.from_rows(
pyexcel.iget_array(
file_type=extension,
file_stream=file_content),
filename)
pyexcel.iget_array(file_type=extension, file_stream=file_content), filename
)
pyexcel.free_resources()
return instance