From 4d5f95c868203239ba14be6551849e62405235fa Mon Sep 17 00:00:00 2001 From: taylor85345 Date: Thu, 13 Jan 2022 09:12:08 -0700 Subject: [PATCH 1/5] Added function to print comic information to STDOUT --- xkcd.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xkcd.py b/xkcd.py index dd38245..9bfc03a 100644 --- a/xkcd.py +++ b/xkcd.py @@ -29,10 +29,18 @@ def cli(random): res = s.get(data["img"]) img = Image.open(BytesIO(res.content)) img.show() + print("Title: ", data["title"]) + print("Number:", data["num"]) + print("Date: ", data["month"]+"/"+data["day"]+"/"+data["year"]) + print("Alt: ", data["alt"]) else: res = s.get(data["img"]) img = Image.open(BytesIO(res.content)) img.show() + print("Title: ", data["title"]) + print("Number:", data["num"]) + print("Date: ", data["month"]+"/"+data["day"]+"/"+data["year"]) + print("Alt: ", data["alt"]) except requests.ConnectionError: error_image = Image.open("assets/xkcd_404.jpg") From 5bac34afa9fcd21a991394ae4b8f847129456a82 Mon Sep 17 00:00:00 2001 From: taylor85345 <36456160+taylor85345@users.noreply.github.com> Date: Thu, 13 Jan 2022 11:35:07 -0700 Subject: [PATCH 2/5] Updating date to ISO format per suggestion --- xkcd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xkcd.py b/xkcd.py index 9bfc03a..cd641cd 100644 --- a/xkcd.py +++ b/xkcd.py @@ -31,7 +31,7 @@ def cli(random): img.show() print("Title: ", data["title"]) print("Number:", data["num"]) - print("Date: ", data["month"]+"/"+data["day"]+"/"+data["year"]) + print("Date: ", data["year"]+"/"+data["month"]+"/"+data["day"]) print("Alt: ", data["alt"]) else: res = s.get(data["img"]) @@ -39,7 +39,7 @@ def cli(random): img.show() print("Title: ", data["title"]) print("Number:", data["num"]) - print("Date: ", data["month"]+"/"+data["day"]+"/"+data["year"]) + print("Date: ", data["year"]+"/"+data["month"]+"/"+data["day"]) print("Alt: ", data["alt"]) except requests.ConnectionError: From e0c3eb6ab7e51211d31745d69b2de6f5dd0fac9c Mon Sep 17 00:00:00 2001 From: taylor85345 Date: Thu, 13 Jan 2022 12:37:38 -0700 Subject: [PATCH 3/5] Made Metadata and Image Display optional functions --- xkcd.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xkcd.py b/xkcd.py index cd641cd..00f9f75 100644 --- a/xkcd.py +++ b/xkcd.py @@ -8,7 +8,9 @@ @click.command() @click.option('--random', flag_value='random', default=False, help='Get Random Comic!') -def cli(random): +@click.option('--metadata', flag_value='metadata', default=False, help='Print Comic Metadata to Terminal') +@click.option('--noimage', flag_value='noimage', default=False, help='Do not display comic image.') +def cli(random,metadata,noimage): """XKCD Terminal Tool""" try: from sh import lolcat, figlet # Hacky fix for Build to pass system packages @@ -26,12 +28,18 @@ def cli(random): endpoint = "https://xkcd.com/{}/info.0.json".format(rand_digits) content = s.get(endpoint).content.decode() data = json.loads(content) + + if noimage != "noimage": res = s.get(data["img"]) img = Image.open(BytesIO(res.content)) img.show() + + if metadata == 'metadata': print("Title: ", data["title"]) print("Number:", data["num"]) print("Date: ", data["year"]+"/"+data["month"]+"/"+data["day"]) +<<<<<<< HEAD +======= print("Alt: ", data["alt"]) else: res = s.get(data["img"]) @@ -40,6 +48,7 @@ def cli(random): print("Title: ", data["title"]) print("Number:", data["num"]) print("Date: ", data["year"]+"/"+data["month"]+"/"+data["day"]) +>>>>>>> 5bac34afa9fcd21a991394ae4b8f847129456a82 print("Alt: ", data["alt"]) except requests.ConnectionError: From 0b8c4cdf92129c20bcaeb65bfd7fc68926171479 Mon Sep 17 00:00:00 2001 From: taylor85345 Date: Thu, 13 Jan 2022 12:58:35 -0700 Subject: [PATCH 4/5] Fixed Garbage output in previous commit --- xkcd.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/xkcd.py b/xkcd.py index 00f9f75..d2a6b54 100644 --- a/xkcd.py +++ b/xkcd.py @@ -38,18 +38,7 @@ def cli(random,metadata,noimage): print("Title: ", data["title"]) print("Number:", data["num"]) print("Date: ", data["year"]+"/"+data["month"]+"/"+data["day"]) -<<<<<<< HEAD -======= - print("Alt: ", data["alt"]) - else: - res = s.get(data["img"]) - img = Image.open(BytesIO(res.content)) - img.show() - print("Title: ", data["title"]) - print("Number:", data["num"]) - print("Date: ", data["year"]+"/"+data["month"]+"/"+data["day"]) ->>>>>>> 5bac34afa9fcd21a991394ae4b8f847129456a82 - print("Alt: ", data["alt"]) + print("alt: ", data ["alt"]) except requests.ConnectionError: error_image = Image.open("assets/xkcd_404.jpg") From 3e31b09f8dd518518c7005127dbee50e66be1388 Mon Sep 17 00:00:00 2001 From: taylor85345 Date: Thu, 13 Jan 2022 18:01:38 -0700 Subject: [PATCH 5/5] Made Title and Number print by default --- xkcd.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xkcd.py b/xkcd.py index d2a6b54..3014f5b 100644 --- a/xkcd.py +++ b/xkcd.py @@ -34,9 +34,10 @@ def cli(random,metadata,noimage): img = Image.open(BytesIO(res.content)) img.show() + print("Title: ", data["title"]) + print("Number:", data["num"]) + if metadata == 'metadata': - print("Title: ", data["title"]) - print("Number:", data["num"]) print("Date: ", data["year"]+"/"+data["month"]+"/"+data["day"]) print("alt: ", data ["alt"])