diff --git a/octoprint_printhistory/export.py b/octoprint_printhistory/export.py index b9ba547..35a89ad 100644 --- a/octoprint_printhistory/export.py +++ b/octoprint_printhistory/export.py @@ -9,6 +9,7 @@ def exportHistoryData(self, exportType): import sys if sys.version_info >= (3,0): from io import StringIO + from io import BytesIO import csv else: from StringIO import StringIO @@ -89,6 +90,9 @@ def exportHistoryData(self, exportType): elif exportType == 'excel': import xlsxwriter + if sys.version_info >= (3,0): + si = BytesIO() + workbook = xlsxwriter.Workbook(si) worksheet = workbook.add_worksheet() for column, header in enumerate(headers): diff --git a/octoprint_printhistory/utils.py b/octoprint_printhistory/utils.py index 4e0763a..707c50e 100644 --- a/octoprint_printhistory/utils.py +++ b/octoprint_printhistory/utils.py @@ -20,7 +20,7 @@ def rename_duplicates(immutable, mutable, prefix): """ for value in mutable: if value in immutable: - mutable[mutable.index(value)] = str(prefix) + value + value = str(prefix) + value return mutable def namedtuple_with_defaults(typename, field_names, default_values=()): @@ -29,7 +29,7 @@ def namedtuple_with_defaults(typename, field_names, default_values=()): """ T = collections.namedtuple(typename, field_names) T.__new__.__defaults__ = (None,) * len(T._fields) - if isinstance(default_values, collections.Mapping): + if isinstance(default_values, collections.abc.Mapping): prototype = T(**default_values) else: prototype = T(*default_values) @@ -40,6 +40,6 @@ def load_json(dictionary, key): parameters_json = dictionary.get(key) try: parameters = json.loads(parameters_json) - except ValueError: + except: parameters = {} return parameters