Skip to content

Commit 8801773

Browse files
author
Jason Belk
committed
initial data from pybites
1 parent 64808d1 commit 8801773

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''Extract datetimes from log entries and calculate the time
2+
between the first and last shutdown events'''
3+
from datetime import datetime
4+
import os
5+
import urllib.request
6+
7+
SHUTDOWN_EVENT = 'Shutdown initiated'
8+
9+
# prep: read in the logfile
10+
logfile = os.path.join('/tmp', 'log')
11+
urllib.request.urlretrieve('http://bit.ly/2AKSIbf', logfile)
12+
13+
with open(logfile) as f:
14+
loglines = f.readlines()
15+
16+
17+
# for you to code:
18+
19+
def convert_to_datetime(line):
20+
'''TODO 1:
21+
Given a log line extract its timestamp and convert it to a datetime object.
22+
For example calling the function with:
23+
INFO 2014-07-03T23:27:51 supybot Shutdown complete.
24+
returns:
25+
datetime(2014, 7, 3, 23, 27, 51)'''
26+
pass
27+
28+
29+
def time_between_shutdowns(loglines):
30+
'''TODO 2:
31+
Extract shutdown events ("Shutdown initiated") from loglines and calculate the
32+
timedelta between the first and last one.
33+
Return this datetime.timedelta object.'''
34+
pass

0 commit comments

Comments
 (0)