from datetime import datetime


def _construct_message(msg):
    """Formats a message from a dictionary

    Parameters
    ----------
    msg: dict
        The message in dict form

    Returns
    -------
    str
        A stringified version of the message
    """

    date = datetime.fromisoformat(msg['timestamp'].split('.')[0])
    msg_string = f"Nytt trafikmeddelande för {msg['title']}, "
    msg_string += f"{date.month}/{date.day} {date.hour}:{date.minute}. "
    msg_string += f"{msg['priority']}, {msg['category']}: {msg['description']} "
    if msg['location'] is not None:
        msg_string += f"Exakt plats: {msg['location']}."
    return msg_string