Skip to content

Commit 894ef72

Browse files
committed
bunch of days through day 55
1 parent 778f75f commit 894ef72

File tree

9 files changed

+10584
-39
lines changed

9 files changed

+10584
-39
lines changed

days/01-03-datetimes/da1_bite67.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from datetime import date, timedelta
2+
3+
start_100days = date(2017, 3, 30)
4+
pybites_founded = date(2016, 12, 19)
5+
pycon_date = date(2018, 5, 8)
6+
7+
8+
def get_hundred_days_end_date(start_100days):
9+
"""Return a string of yyyy-mm-dd"""
10+
return str(start_100days - timedelta(days=100))
11+
12+
13+
def get_days_between_pb_start_first_joint_pycon(pybites_founded, pycon_date):
14+
"""Return the int number of days"""
15+
return int((pycon_date - pybites_founded).days)
16+
17+
print(get_days_between_pb_start_first_joint_pycon(pybites_founded, pycon_date))

days/01-03-datetimes/day1.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from datetime import datetime
2+
3+
SHUTDOWN_EVENT = 'Shutdown initiated'
4+
5+
loglines = ["ERROR 2014-07-03T23:24:31 supybot Invalid user dictionary file, resetting to empty.",
6+
"ERROR 2014-07-03T23:24:31 supybot Exact error: IOError: [Errno 2] No such file or directory: 'conf/users.conf'",
7+
"ERROR 2014-07-03T23:24:31 supybot Invalid channel database, resetting to empty.",
8+
"ERROR 2014-07-03T23:24:31 supybot Exact error: IOError: [Errno 2] No such file or directory: 'conf/channels.conf'",
9+
"WARNING 2014-07-03T23:24:31 supybot Couldn't open ignore database: [Errno 2] No such file or directory: 'conf/ignores.conf'",
10+
"INFO 2014-07-03T23:27:51 supybot Shutdown initiated.",
11+
"INFO 2014-07-03T23:27:51 supybot Killing Driver objects.",
12+
"INFO 2014-07-03T23:27:51 supybot Killing Irc objects.",
13+
"INFO 2014-07-03T23:27:51 supybot Shutdown complete.",
14+
"INFO 2014-07-03T23:30:37 supybot Creating new Irc for freenode.",
15+
"INFO 2014-07-03T23:30:37 supybot Connecting to irc.freenode.net:8001.",
16+
"INFO 2014-07-03T23:30:38 supybot Loading plugins (connecting to freenode).",
17+
"INFO 2014-07-03T23:30:46 supybot Server orwell.freenode.net has version ircd-seven-1.1.3",
18+
"INFO 2014-07-03T23:30:48 supybot Got end of MOTD from orwell.freenode.net",
19+
"INFO 2014-07-03T23:30:54 supybot Join to #timvideos on freenode synced in 2.41 seconds.",
20+
"INFO 2014-07-03T23:31:22 supybot Exiting due to Ctrl-C. If the bot doesn't exit within a few seconds, feel free to press Ctrl-C again to make it exit without flushing its message queues.",
21+
"INFO 2014-07-03T23:31:22 supybot Flushers flushed and garbage collected.",
22+
"INFO 2014-07-03T23:31:22 supybot Driver for Irc object for freenode dying.",
23+
"INFO 2014-07-03T23:31:22 supybot Irc object for freenode dying.",
24+
"INFO 2014-07-03T23:31:22 supybot Driver for Irc object for freenode dying.",
25+
"WARNING 2014-07-03T23:31:22 supybot Disconnect from irc.freenode.net:8001: error: [Errno 9] Bad file descriptor.",
26+
"INFO 2014-07-03T23:31:22 supybot Reconnecting to freenode at 2014-07-03T23:31:32.",
27+
"INFO 2014-07-03T23:31:22 supybot Removing driver SocketDriver(Irc object for freenode).",
28+
"INFO 2014-07-03T23:31:22 supybot Total uptime: 45 seconds.",
29+
"INFO 2014-07-03T23:31:22 supybot Total CPU time taken: 1.12 seconds.",
30+
"INFO 2014-07-03T23:31:22 supybot No more Irc objects, exiting.",
31+
"INFO 2014-07-03T23:31:22 supybot Shutdown initiated.",
32+
"INFO 2014-07-03T23:31:22 supybot Killing Driver objects.",
33+
"INFO 2014-07-03T23:31:22 supybot Killing Irc objects.",
34+
"INFO 2014-07-03T23:31:22 supybot Writing registry file to planet-news.conf",
35+
"INFO 2014-07-03T23:31:22 supybot Finished writing registry file.",
36+
"INFO 2014-07-03T23:31:22 supybot Shutdown complete."]
37+
38+
39+
def convert_to_datetime(line):
40+
'''TODO 1:
41+
Given a log line extract its timestamp and convert it to a datetime object.
42+
For example calling the function with:
43+
INFO 2014-07-03T23:27:51 supybot Shutdown complete.
44+
returns:
45+
datetime(2014, 7, 3, 23, 27, 51)'''
46+
return datetime.strptime(line.split(" ")[1], "%Y-%m-%dT%H:%M:%S")
47+
48+
def time_between_shutdowns(loglines):
49+
'''TODO 2:
50+
Extract shutdown events ("Shutdown initiated") from loglines and calculate the
51+
timedelta between the first and last one.
52+
Return this datetime.timedelta object.'''
53+
#shutdown_entries = [line for line in loglines if SHUTDOWN_EVENT in line]
54+
#print(shutdown_entries)
55+
initiate = []
56+
for line in loglines:
57+
line_split = line.rstrip().split(" ")
58+
if " ".join(line_split[-2:]) == "Shutdown initiated.":
59+
initiate.append(convert_to_datetime(line))
60+
print(initiate)
61+
return initiate[-1] - initiate[0]
62+
63+
line1 = 'ERROR 2014-07-03T23:24:31 supybot Invalid user dictionary file'
64+
line2 = 'INFO 2015-10-03T10:12:51 supybot Shutdown initiated.'
65+
line3 = 'INFO 2016-09-03T02:11:22 supybot Shutdown complete.'
66+
67+
a = convert_to_datetime(line1)
68+
b = convert_to_datetime(line2)
69+
70+
print(time_between_shutdowns(loglines))

days/01-03-datetimes/day1_bite7.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from datetime import datetime
2+
3+
loglines = ["ERROR 2014-07-03T23:24:31 supybot Invalid user dictionary file, resetting to empty.",
4+
"ERROR 2014-07-03T23:24:31 supybot Exact error: IOError: [Errno 2] No such file or directory: 'conf/users.conf'",
5+
"ERROR 2014-07-03T23:24:31 supybot Invalid channel database, resetting to empty.",
6+
"ERROR 2014-07-03T23:24:31 supybot Exact error: IOError: [Errno 2] No such file or directory: 'conf/channels.conf'",
7+
"WARNING 2014-07-03T23:24:31 supybot Couldn't open ignore database: [Errno 2] No such file or directory: 'conf/ignores.conf'",
8+
"INFO 2014-07-03T23:27:51 supybot Shutdown initiated.",
9+
"INFO 2014-07-03T23:27:51 supybot Killing Driver objects.",
10+
"INFO 2014-07-03T23:27:51 supybot Killing Irc objects.",
11+
"INFO 2014-07-03T23:27:51 supybot Shutdown complete.",
12+
"INFO 2014-07-03T23:30:37 supybot Creating new Irc for freenode.",
13+
"INFO 2014-07-03T23:30:37 supybot Connecting to irc.freenode.net:8001.",
14+
"INFO 2014-07-03T23:30:38 supybot Loading plugins (connecting to freenode).",
15+
"INFO 2014-07-03T23:30:46 supybot Server orwell.freenode.net has version ircd-seven-1.1.3",
16+
"INFO 2014-07-03T23:30:48 supybot Got end of MOTD from orwell.freenode.net",
17+
"INFO 2014-07-03T23:30:54 supybot Join to #timvideos on freenode synced in 2.41 seconds.",
18+
"INFO 2014-07-03T23:31:22 supybot Exiting due to Ctrl-C. If the bot doesn't exit within a few seconds, feel free to press Ctrl-C again to make it exit without flushing its message queues.",
19+
"INFO 2014-07-03T23:31:22 supybot Flushers flushed and garbage collected.",
20+
"INFO 2014-07-03T23:31:22 supybot Driver for Irc object for freenode dying.",
21+
"INFO 2014-07-03T23:31:22 supybot Irc object for freenode dying.",
22+
"INFO 2014-07-03T23:31:22 supybot Driver for Irc object for freenode dying.",
23+
"WARNING 2014-07-03T23:31:22 supybot Disconnect from irc.freenode.net:8001: error: [Errno 9] Bad file descriptor.",
24+
"INFO 2014-07-03T23:31:22 supybot Reconnecting to freenode at 2014-07-03T23:31:32.",
25+
"INFO 2014-07-03T23:31:22 supybot Removing driver SocketDriver(Irc object for freenode).",
26+
"INFO 2014-07-03T23:31:22 supybot Total uptime: 45 seconds.",
27+
"INFO 2014-07-03T23:31:22 supybot Total CPU time taken: 1.12 seconds.",
28+
"INFO 2014-07-03T23:31:22 supybot No more Irc objects, exiting.",
29+
"INFO 2014-07-03T23:31:22 supybot Shutdown initiated.",
30+
"INFO 2014-07-03T23:31:22 supybot Killing Driver objects.",
31+
"INFO 2014-07-03T23:31:22 supybot Killing Irc objects.",
32+
"INFO 2014-07-03T23:31:22 supybot Writing registry file to planet-news.conf",
33+
"INFO 2014-07-03T23:31:22 supybot Finished writing registry file.",
34+
"INFO 2014-07-03T23:31:22 supybot Shutdown complete."]
35+
36+
37+
def convert_to_datetime(line):
38+
'''TODO 1:
39+
Given a log line extract its timestamp and convert it to a datetime object.
40+
For example calling the function with:
41+
INFO 2014-07-03T23:27:51 supybot Shutdown complete.
42+
returns:
43+
datetime(2014, 7, 3, 23, 27, 51)'''
44+
return datetime.strptime(line.split(" ")[1], "%Y-%m-%dT%H:%M:%S")
45+
46+
47+
def time_between_shutdowns(loglines):
48+
'''TODO 2:
49+
Extract shutdown events ("Shutdown initiated") from loglines and calculate the
50+
timedelta between the first and last one.
51+
Return this datetime.timedelta object.'''
52+
initiate = []
53+
for line in loglines:
54+
line_split = line.rstrip().split(" ")
55+
if " ".join(line_split[-2:]) == "Shutdown initiated.":
56+
initiate.append(convert_to_datetime(line))
57+
print(initiate)
58+
return initiate[-1] - initiate[0]
59+
60+
line1 = 'ERROR 2014-07-03T23:24:31 supybot Invalid user dictionary file'
61+
line2 = 'INFO 2015-10-03T10:12:51 supybot Shutdown initiated.'
62+
line3 = 'INFO 2016-09-03T02:11:22 supybot Shutdown complete.'
63+
64+
a = convert_to_datetime(line1)
65+
b = convert_to_datetime(line2)
66+
67+
print(time_between_shutdowns(loglines))

days/01-03-datetimes/day1_pomodoro.py

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Enter task name
2+
# Set the timer (default 25 minutes)
3+
# Give updates every minute
4+
# Timer rings, print ASCII
5+
# Check if task is done
6+
# If task is done, add task to done list
7+
# If total tasks % 4 isn't 0, short break (3-5 minutes), start at the top
8+
# If tasks % 4 == 0, take a break (15-30 minutes)
9+
# Setup logging to write out completed tasks and timestamp - other stats?
10+
# Setup a way to leave the timer
11+
# Dialog to start, stop or exit
12+
13+
import time
14+
15+
from datetime import datetime, timedelta
16+
17+
18+
def choose_tasks(tasks_todo=[]):
19+
""" Manages items from the task list
20+
Args:
21+
tasks_todo - list, contains items to complete
22+
"""
23+
print()
24+
print("What task do you want to complete?\n")
25+
for num, task in enumerate(tasks_todo, 1):
26+
print(f"{num}. {task}\n")
27+
task_choice = input("Choose from the list or enter a new task: ")
28+
return(task_choice)
29+
30+
31+
def set_current_task(task_choice, tasks_todo):
32+
if not task_choice.isdigit():
33+
tasks_todo.append(task_choice)
34+
current_task = task_choice
35+
else:
36+
current_task = tasks_todo[int(task_choice)-1]
37+
return current_task
38+
39+
40+
def get_parameters():
41+
""" TODO - Could also add something to check if int"""
42+
focus = None
43+
short_break = None
44+
long_break = None
45+
46+
while True:
47+
focus = input("How long do you want the working "
48+
"sessions to be? (20-30 minutes): ")
49+
if 20 <= int(focus) <= 30:
50+
break
51+
else:
52+
print("Please enter a number between 20 and 30")
53+
54+
while True:
55+
short_break = input("How long do you want the short "
56+
"breaks to be? (2-5 minutes): ")
57+
if 2 <= int(short_break) <= 5:
58+
break
59+
else:
60+
print("Please enter a number between 2 and 5")
61+
62+
while True:
63+
long_break = input("How long do you want the long "
64+
"break to be? (15-30 minutes): ")
65+
if 15 <= int(long_break) <= 30:
66+
break
67+
else:
68+
print("Please enter a number between 15 and 30")
69+
70+
return {"focus": int(focus), "short_break": int(short_break), "long_break": int(long_break)}
71+
72+
73+
def setup_pomodoro(current_task, focus=25, short_break=3, long_break=20):
74+
""" Sets up the basic rules of the pomodor.
75+
Args:
76+
current_task: str - thing we're doing
77+
focus: int - total working length
78+
short_break: int - short break length
79+
long_break: int - break after 4 pomodoros
80+
"""
81+
pomodoros = 0
82+
83+
while True:
84+
# start focus timer
85+
work()
86+
manage_timer(focus, "working")
87+
pomodoros += 1
88+
if pomodoros % 4:
89+
take_break()
90+
manage_timer(long_break, "on a long break")
91+
else:
92+
take_break()
93+
manage_timer(short_break, "on a short break")
94+
95+
96+
def manage_timer(timer, timer_type):
97+
"""TODO:
98+
Use keyboard interrupt to pause
99+
Give minute by minute time updates
100+
Print what the instructions are
101+
"""
102+
print(f"You're currently {timer_type}.\nYou have {timer} minutes remaining")
103+
try:
104+
t = timedelta(minutes=timer).seconds
105+
time.sleep(t)
106+
except KeyboardInterrupt:
107+
print("Jigga what?")
108+
109+
110+
def convert_time(interval):
111+
"""Converts user input into datetime objects"""
112+
converted_time = datetime.strptime(str(interval), "%M")
113+
return converted_time.seconds
114+
115+
116+
def start_now_pomo():
117+
"""TODO Deal with completed tasks and reset pomo"""
118+
119+
120+
def take_break():
121+
"""ASCII Amazingness for break time - crawford2"""
122+
print(r"""
123+
______ ____ __ _ ___ ____ ____ ____ ___ ____ __ _ __
124+
| | / || |/ ] / _] / | | \ | \ / _] / || |/ ]| |
125+
| || o || ' / / [_ | o | | o )| D ) / [_ | o || ' / | |
126+
|_| |_|| || \ | _] | | | || / | _]| || \ |__|
127+
| | | _ || \| [_ | _ | | O || \ | [_ | _ || \ __
128+
| | | | || . || | | | | | || . \| || | || . || |
129+
|__| |__|__||__|\_||_____| |__|__| |_____||__|\_||_____||__|__||__|\_||__|
130+
""")
131+
132+
133+
def work():
134+
"""ASCII Amazingness for break time - crawford2"""
135+
print(r"""
136+
__ __ ___ ____ __ _
137+
| |__| | / \ | \ | |/ ]
138+
| | | || || D )| ' /
139+
| | | || O || / | \
140+
| ` ' || || \ | \
141+
\ / | || . \| . |
142+
\_/\_/ \___/ |__|\_||__|\_|
143+
""")
144+
145+
146+
def complete_tasks(tasks_todo, tasks_complete, current_task):
147+
tasks_todo.remove(current_task)
148+
tasks_complete.append(current_task)
149+
150+
151+
def first_time():
152+
tasks_todo = []
153+
tasks_complete = []
154+
155+
task_choice = choose_tasks()
156+
print()
157+
current_task = set_current_task(task_choice, tasks_todo)
158+
params = get_parameters()
159+
setup_pomodoro(current_task, **params)
160+
161+
162+
first_time()

0 commit comments

Comments
 (0)