Skip to content

Commit

Permalink
Added updated initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
ReTeam Labs committed May 5, 2020
1 parent 504627a commit 6e10e78
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build:
docker build -t python-build-cli-planner-app .

test: build
docker run -t python-build-cli-planner-app pytest /app/tests/tests.py
docker run -t python-build-cli-planner-app pytest --verbose /app/tests/tests.py

start: build
docker run -it python-build-cli-planner-app
docker run -it python-build-cli-planner-app
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# python-build-cli-planner-app

In this project you will implement a simple reminder app with a command line interface (CLI). While doing so, you will learn how to use inheritance and abstract base classes to make your code modular and to ensure a contract between your classes.

First, we will guide you through implementing simple text reminders. Then, you will have reminders with a deadline, which is either a date, or a date and a time. As each of these have their own class, you will see how these can play together nicely. This basis makes it easy for you to go beyond the course scope and implement other types of reminders, such as recurrent ones.

## Setup

You should have [Docker](https://www.docker.com/products/docker-desktop) installed, as well as `make`. These ensure the app is easy to run regardless of your platform.

### Play with the app

Now that you have all the requirements ready, you can test the app by running `make` in the root directory. You can add a new reminder, or list the ones you have already added.

Try adding a couple of reminders, such as *Drink water*, *Take a break* or *Buy some milk*.

### Test the app

To test your app, run `make test`. Since you have not implemented anything, all the tests should be failing. As you progress through the tasks, more and more of them will pass. When you are stuck, running the tests may give you a hint about your error.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest==5.3.5
python-dateutil==2.8.1
pytest-json-report==1.2.1
32 changes: 21 additions & 11 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
from database import add_reminder, list_reminders
from src.database import add_reminder, list_reminders

def handle_input(input):
if(input == "1"):

def handle_input():
choice = input("Choice: ")
if choice == "3":
return False

if(choice == "1"):
list_reminders()
print_menu()
elif(input == "2"):
add_reminder()

elif(choice == "2"):
print()
reminder = input("What would you like to be reminded about?: ")

add_reminder(reminder)
list_reminders()
print_menu()
else:
print("Invalid menu option")
print_menu()

return True

def print_menu():
print()
Expand All @@ -24,10 +32,12 @@ def print_menu():
print()
print('1) List reminders')
print('2) Add a reminder')
choice = input("Choice: ")
handle_input(choice)
print('3) Exit')

def main():
print_menu()
while handle_input():
print_menu()

main()
if __name__ == '__main__':
main()
12 changes: 3 additions & 9 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ def list_reminders():
print(e.ljust(32), end=' ')
print()

<<<<<<< HEAD
def add_reminder():
=======
def add_reminder(reminder):
>>>>>>> 953bcebd1437acfa83993b25cca4faf463989db8
print()
reminder = input("What would you like to be reminded about?: ")

def add_reminder(text):

with open('reminders.csv', 'a+', newline='\n') as file:
writer = csv.writer(file)
writer.writerow([reminder])
writer.writerow([text])
31 changes: 31 additions & 0 deletions src/external_reminders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""This module implements some Reminder classes that we should
consider as "external", whose source we do not control.
"""
from dateutil.parser import parse
from collections.abc import Iterable

class DateTimeReminder(Iterable):
"""A reminder which has a specific date and time for being due"""
def __init__(self, text: str, date: str, time: str = '9am'):
self.text = text
self.date = parse(f'{date} {time}')
self.time = self.date.time()

def __iter__(self):
return iter([self.text,
self.date.strftime("%m/%d/%YT%H:%M:%SZ"),
self.time.strftime('%I:%M %p')])

def is_due(self):
return self.date < datetime.now()


class MorningReminder(DateTimeReminder):
"""A reminder that is due at 9am"""
def __init__(self, text: str, date: str):
super().__init__(text, date, '9am')

class EveningReminder(DateTimeReminder):
"""A reminder that is due at 8pm"""
def __init__(self, text: str, date: str):
super().__init__(text, date, '8pm')
7 changes: 7 additions & 0 deletions src/reminder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class PrefixedReminder:
"""This class acts as a base class for other types of reminders.
Classes that subclass it should override the `self.text` property
"""
def __init__(self, prefix="Hey, don't forget to "):
self.prefix = prefix
self.text = prefix + '<placeholder_text>'

0 comments on commit 6e10e78

Please sign in to comment.