# -*- encoding: utf-8 -*- import logging from tempfile import NamedTemporaryFile import typing as T from latecomers.parse import Details from latecomers.helpers import logit import pandas as pd logger = logging.getLogger(__name__) @logit(logger) def to_excel(data: T.List[Details]) -> bytes: """ This function takes the list of parsed rows as input and returns the bytes corresponding to the excel file derived from such lines. """ mapping = { "th_arrival": "Arrivo teorico", "real_arrival": "Arrivo reale", "code": "Codice volo", "origin": "Aeroporto di partenza", "status": "Stato", } df = pd.DataFrame(data, columns=mapping) with NamedTemporaryFile() as tmp: df.to_excel(tmp) tmp.seek(0) content = tmp.read() return content