from datetime import datetime


def parse_line_item(line_item):
    """ Given an OFX line item, transform it into a friendlier dict of the
        data we need.

    """
    date_posted_str = line_item.get('DTPOSTED', '')
    try:
       date_posted = datetime.strptime(date_posted_str, "%Y%m%d%H%M%S.000")
    except ValueError:
       date_posted = datetime.strptime(date_posted_str, "%Y%m%d%H%M%S")
    return {
        "name": line_item.get('NAME'),
        "date_posted": date_posted,
        "transaction_type": line_item.get('TRNTYPE'),
        "amount": line_item.get('TRNAMT'),
        "check_number": line_item.get('CHECKNUM'),
        "id": line_item.get('FITID')
    }