import time

res = []
entry = demisto.executeCommand('xb-timeline', {'username': demisto.args()['username']})[0]
if entry['Type'] != entryTypes['error'] and entry['ContentsFormat'] == formats['json']:
    entities = demisto.get(entry, 'Contents.entities')
    if entities:
        for e in entities:
            res.append({'1.ID': demisto.get(e, 'id'), '2.Type': demisto.get(e, 'tp'), '3.Start': time.ctime(demisto.get(e, 'st') / 1000.0), '4.End': time.ctime(demisto.get(e, 'et') / 1000.0), \
                        '5.Initial Risk': str(demisto.get(e, 'irs')), '6.Risk': str(demisto.get(e, 'rs')), '7.OS': str(demisto.get(e, 'os')), '8.OE': str(demisto.get(e, 'oe'))})
    demisto.results({'ContentsFormat': formats['table'], 'Type': entryTypes['note'], 'Contents': res})
else:
    demisto.results(entry)
