':param limit: The maximum number of elements to return
:param action: The type of action to filter in the history. Either \'downloaded\' or \'snatched\'. Anything else or
no value will return everything (up to ``limit``)
:return: The last ``limit`` elements of type ``action`` in the history'

def get(self, limit=100, action=None):

    data = []
    action = (action.lower() if isinstance(action, str) else u'')
    limit = int(limit)
    if (action == u'downloaded'):
        actions = Quality.DOWNLOADED
    elif (action == u'snatched'):
        actions = Quality.SNATCHED
    else:
        actions = []
    for tv_show in [x[u'doc'] for x in sickrage.srCore.mainDB.db.all(u'tv_shows', with_doc=True)]:
        if (limit == 0):
            if (len(actions) > 0):
                dbData = [x[u'doc'] for x in sickrage.srCore.mainDB.db.get_many(u'history', tv_show[u'indexer_id'], with_doc=True) if (x[u'doc'][u'action'] in actions)]
            else:
                dbData = [x[u'doc'] for x in sickrage.srCore.mainDB.db.get_many(u'history', tv_show[u'indexer_id'], with_doc=True)]
        elif (len(actions) > 0):
            dbData = [x[u'doc'] for x in sickrage.srCore.mainDB.db.get_many(u'history', tv_show[u'indexer_id'], limit, with_doc=True) if (x[u'doc'][u'action'] in actions)]
        else:
            dbData = [x[u'doc'] for x in sickrage.srCore.mainDB.db.get_many(u'history', tv_show[u'indexer_id'], limit, with_doc=True)]
        for result in dbData:
            data.append({u'action': result[u'action'], u'date': result[u'date'], u'episode': result[u'episode'], u'provider': result[u'provider'], u'quality': result[u'quality'], u'resource': result[u'resource'], u'season': result[u'season'], u'show_id': result[u'showid'], u'show_name': tv_show[u'show_name']})
    return sorted(data, key=(lambda d: d[u'date']), reverse=True)
