Skip to content

Commit 1697de3

Browse files
author
Calvin Gutierrez
committed
simple pomodoro completed
1 parent 77ede0b commit 1697de3

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

days/01-03-datetimes/bite7.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from datetime import datetime
2+
import os
3+
import urllib.request
4+
5+
SHUTDOWN_EVENT = 'Shutdown initiated'
6+
7+
# prep: read in the logfile
8+
tmp = os.getenv("TMP", "/tmp")
9+
logfile = os.path.join(tmp, 'log')
10+
urllib.request.urlretrieve(
11+
'https://bites-data.s3.us-east-2.amazonaws.com/messages.log',
12+
logfile
13+
)
14+
15+
with open(logfile) as f:
16+
loglines = f.readlines()
17+
18+
19+
# for you to code:
20+
21+
def convert_to_datetime(line):
22+
"""TODO 1:
23+
Extract timestamp from logline and convert it to a datetime object.
24+
For example calling the function with:
25+
INFO 2014-07-03T23:27:51 supybot Shutdown complete.
26+
returns:
27+
datetime(2014, 7, 3, 23, 27, 51)
28+
"""
29+
pass
30+
31+
32+
def time_between_shutdowns(loglines):
33+
"""TODO 2:
34+
Extract shutdown events ("Shutdown initiated") from loglines and
35+
calculate the timedelta between the first and last one.
36+
Return this datetime.timedelta object.
37+
"""
38+
pass
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from datetime import timedelta
2+
import time
3+
4+
5+
def main():
6+
seconds_1 = timedelta(seconds=1)
7+
seconds_20 = timedelta(seconds=20*60)
8+
while seconds_20 != timedelta(seconds=0):
9+
print(seconds_20)
10+
time.sleep(1)
11+
seconds_20 = seconds_20 - seconds_1
12+
print('times up!')
13+
14+
15+
if __name__ == '__main__':
16+
main()

0 commit comments

Comments
 (0)