From 5be1c787a57316a07bc3ff9718239fda8ffdba73 Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Wed, 3 Dec 2025 14:36:50 +0200 Subject: [PATCH 1/9] gitignore updated --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3c3629e64..5da303acc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +**/.venv +**/requirements.txt From 3895c1cc43cfad8c29c2e42a2fd4298770128521 Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Thu, 4 Dec 2025 09:57:24 +0200 Subject: [PATCH 2/9] cow.py file added and project setup with requirements.txt --- implement-cowsay/cow.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 implement-cowsay/cow.py diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100644 index 000000000..a0b6ba312 --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1 @@ +import cowsay \ No newline at end of file From 8671d12f61bfbd034e1708ecfa37eb5eaa2ef8bd Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Thu, 4 Dec 2025 10:21:46 +0200 Subject: [PATCH 3/9] argparse setup for project --- implement-cowsay/cow.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index a0b6ba312..5582c4769 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -1 +1,19 @@ -import cowsay \ No newline at end of file +import cowsay +import argparse + +parser = argparse.ArgumentParser( + prog="cowsay", + description="Make animals say things" +) + +parser.add_argument("--animal", help="The animal to be saying things.") +parser.add_argument("message", nargs="+", help="The message to say.") + +args = parser.parse_args() + +# cowsay.cow(" ".join(sys.argv[1:])) + + +animals = cowsay.char_names + +print(animals) \ No newline at end of file From 62bd86e53127b7621c4296127aa3550740a7c905 Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Thu, 4 Dec 2025 10:50:30 +0200 Subject: [PATCH 4/9] Basic logic complete --- implement-cowsay/cow.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index 5582c4769..b92c85fb9 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -1,19 +1,32 @@ import cowsay import argparse +animals = cowsay.char_names + parser = argparse.ArgumentParser( prog="cowsay", description="Make animals say things" ) -parser.add_argument("--animal", help="The animal to be saying things.") +parser.add_argument("-a", "--animal", choices=animals, help="The animal to be saying things.") parser.add_argument("message", nargs="+", help="The message to say.") args = parser.parse_args() -# cowsay.cow(" ".join(sys.argv[1:])) +message = " ".join(args.message) +print(args) -animals = cowsay.char_names +if args.animal: + # cowsay[args.animal](message) + print(cowsay.get_output_string(args.animal, message)) + # print('hi') +else: + # print(cowsay.get_output_string('cow', 'Hello World')) + cowsay.cow(message) # if no animal is provided, use default + + + +print(animals) -print(animals) \ No newline at end of file + \ No newline at end of file From 7d1e4b76f285bbe8249779356366f5d940d09487 Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Thu, 4 Dec 2025 11:00:35 +0200 Subject: [PATCH 5/9] cowsay implementation complete, code cleaned up --- implement-cowsay/cow.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index b92c85fb9..20d0e51a0 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -1,6 +1,7 @@ import cowsay import argparse +# Get dynamic list of animals from the cowsay library animals = cowsay.char_names parser = argparse.ArgumentParser( @@ -8,25 +9,18 @@ description="Make animals say things" ) -parser.add_argument("-a", "--animal", choices=animals, help="The animal to be saying things.") +parser.add_argument("--animal", choices=animals, help="The animal to be saying things.") parser.add_argument("message", nargs="+", help="The message to say.") args = parser.parse_args() +# Join all message words into a single string message = " ".join(args.message) -print(args) if args.animal: - # cowsay[args.animal](message) - print(cowsay.get_output_string(args.animal, message)) - # print('hi') + cowsay.char_funcs[args.animal](message) else: - # print(cowsay.get_output_string('cow', 'Hello World')) - cowsay.cow(message) # if no animal is provided, use default + # if no animal is provided, use default + cowsay.cow(message) - - -print(animals) - - \ No newline at end of file From bd4f33ec01c82efabcbda6179fe14f0670ec5a9a Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Thu, 4 Dec 2025 11:09:28 +0200 Subject: [PATCH 6/9] Code added into main function as per Python best practice --- implement-cowsay/cow.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index 20d0e51a0..db2116593 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -1,26 +1,27 @@ import cowsay import argparse -# Get dynamic list of animals from the cowsay library -animals = cowsay.char_names +def main(): + # Get dynamic list of animals from the cowsay library + animals = cowsay.char_names -parser = argparse.ArgumentParser( - prog="cowsay", - description="Make animals say things" -) + parser = argparse.ArgumentParser( + prog="cowsay", + description="Make animals say things" + ) -parser.add_argument("--animal", choices=animals, help="The animal to be saying things.") -parser.add_argument("message", nargs="+", help="The message to say.") + parser.add_argument("--animal", choices=animals, help="The animal to be saying things.") + parser.add_argument("message", nargs="+", help="The message to say.") -args = parser.parse_args() + args = parser.parse_args() -# Join all message words into a single string -message = " ".join(args.message) + # Join all message words into a single string + message = " ".join(args.message) + if args.animal: + cowsay.char_funcs[args.animal](message) + else: + cowsay.cow(message) -if args.animal: - cowsay.char_funcs[args.animal](message) -else: - # if no animal is provided, use default - cowsay.cow(message) - +if __name__ == "__main__": + main() From 7125d1a67cdee82c34da41661d4b65d0bd14ce91 Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Thu, 4 Dec 2025 11:17:28 +0200 Subject: [PATCH 7/9] If statement removed and default value added to animal flag --- implement-cowsay/cow.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index db2116593..e5345cbaa 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -10,7 +10,7 @@ def main(): description="Make animals say things" ) - parser.add_argument("--animal", choices=animals, help="The animal to be saying things.") + parser.add_argument("--animal", choices=animals, default="cow",help="The animal to be saying things.") parser.add_argument("message", nargs="+", help="The message to say.") args = parser.parse_args() @@ -18,10 +18,9 @@ def main(): # Join all message words into a single string message = " ".join(args.message) - if args.animal: - cowsay.char_funcs[args.animal](message) - else: - cowsay.cow(message) + # Output the message using the selected animal or the default cow + cowsay.char_funcs[args.animal](message) + if __name__ == "__main__": main() From b3b1526b3261dd5203d29832ac8141be37c625aa Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Tue, 23 Dec 2025 18:12:32 +0200 Subject: [PATCH 8/9] gitignore updated --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5da303acc..da79f9017 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules **/.venv -**/requirements.txt From b808b0635c9707aea31b0d019ce5922db14958c8 Mon Sep 17 00:00:00 2001 From: Rashaad Ebrahim Date: Tue, 23 Dec 2025 18:14:48 +0200 Subject: [PATCH 9/9] requirements.txt added --- implement-cowsay/requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 implement-cowsay/requirements.txt diff --git a/implement-cowsay/requirements.txt b/implement-cowsay/requirements.txt new file mode 100644 index 000000000..cc5571034 --- /dev/null +++ b/implement-cowsay/requirements.txt @@ -0,0 +1 @@ +cowsay \ No newline at end of file