runtime
207 / 500
question 207 Dates Numbers & Regex · medium

Turn event log lines into records

A repository service writes one event per log line: 2025-03-03T00:02:37Z PushEvent ml-koi418 tidewater/smartqueue. Turn the well-formed lines into records and count the ones that aren't.

Functionparse_events(lines)
Shapea UTC time YYYY-MM-DDTHH:MM:SSZ, an event type made of letters ending in Event, an actor login (letters, digits, - or _), and a repository owner/name, separated by single spaces
Returns(records, skipped): a list of {"time", "type", "actor", "repo"} dictionaries in order, and how many lines didn't have the shape
Examples
callparse_events(['2025-03-03T00:02:37Z PushEvent ml-koi418 tidewater/smartqueue', 'garbage'])returns([{'time': '2025-03-03T00:02:37Z', 'type': 'PushEvent', 'actor': 'ml-koi418', 'repo': 'tidewater/smartqueue'}], 1)
callparse_events(['2025-03-03T00:05:10Z WatchEvent dev_ana tidewater/smartqueue', '2025-03-03T00:09:58Z IssuesEvent sam-ops oakline/ledger.v2'])returns([{'time': '2025-03-03T00:05:10Z', 'type': 'WatchEvent', 'actor': 'dev_ana', 'repo': 'tidewater/smartqueue'}, {'time': '2025-03-03T00:09:58Z', 'type': 'IssuesEvent', 'actor': 'sam-ops', 'repo': 'oakline/ledger.v2'}], 0)
callparse_events([])returns([], 0)

Loading your progress…

Turn event log lines into records — Python practice · Runtime