im new to learning python just so you guys know. Im trying to make a function that uses regex to filter out the timestamp from a message log. Im trying to get my test cases to work but im getting an assertion error.
def get_hr_min(row):
time_match = re.search(r'(\d{2}):(\d{2})', row)
hour = time_match.group(1)
minute = time_match.group(2)
dhour = {}
dhour['hour'] = hour
dmin = {}
dmin['minute'] = minute
return dhour, dmin
here is what I have so far. as far as I can tell the function should return the minutes and hours in dictionary format(but I may have formatted it wrong as my professor did not tell me what a dictionary actually is)
log_open_row = '--- Log opened Tue Sep 20 00:01:49 2016'
join_quit_row = '00:01 -!- Guest40341 [[email protected]] has quit [Quit: Bye]'
message_row = '00:25 < ice231> anyone good with exploiting cisco asa with extrabacon?'
#assert get_hr_min(log_open_row) == {}
assert get_hr_min(join_quit_row) == {'hour': 0, 'minute': 1}
assert get_hr_min(message_row) == {'hour': 0, 'minute': 25}
here are my test cases. I get an assertion error when I run these test cases. I need to make an if statement to filter out the first assertion but I wanted to get the dictionary to work first(im assuming that is where my mistake is?). Any help or tips are appreciated.