Skip to content

Instantly share code, notes, and snippets.

@alexwoolford
Last active August 29, 2015 14:21
Show Gist options
  • Save alexwoolford/87a7ccdae834adfcfd3e to your computer and use it in GitHub Desktop.
Save alexwoolford/87a7ccdae834adfcfd3e to your computer and use it in GitHub Desktop.
# In[1]:
import re
import datetime
# In[2]:
log = """[23:40:45]ACCESS: Login: StaffMember/(StaffMember)
[23:41:09]ACCESS: Logout: *no key*/(StaffMember)
[23:41:09]ACCESS: Login: StaffMember/(John Smith)
[23:41:29]ACCESS: Logout: *no key*/(John Smith)
[23:41:29]ACCESS: Login: StaffMember/(John Smith)
[23:41:52]ACCESS: Logout: *no key*/(John Smith)
[23:41:52]ACCESS: Login: StaffMember/(John Smith)"""
# In[3]:
logLinePattern = re.compile("\[(\d\d):(\d\d):(\d\d)\]ACCESS: (Login|Logout):.*/\((.*)\)")
# In[4]:
for line in log.split("\n"):
eventTime = datetime.time(int(re.match(logLinePattern, line).group(1)), \
int(re.match(logLinePattern, line).group(2)), \
int(re.match(logLinePattern, line).group(3)))
eventType = re.match(logLinePattern, line).group(4)
user = re.match(logLinePattern, line).group(5)
print eventTime, eventType, user
# TODO:
# Make a dictionary of events for each user, iterate through the users, sort the events, then iterate through the events capturing the cumulative time between login/logout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment