from datetime import datetime
import time


def get_entry_datetime(entry):
    """
    Convert the published attribute or, if the former is lacking, the
    updated attribute of a feed entry to a datetime object

    Parameters
    ----------
    entry : feedparser.FeedParserDict
        a feed entry

    Returns
    -------
    etime : datetime.datetime
        timestamp of the entry
    """

    try:
        etime = datetime.fromtimestamp(time.mktime(entry.published_parsed))
    except AttributeError:
        etime = datetime.fromtimestamp(time.mktime(entry.updated_parsed))
    return etime