From d1a3aba9a7eff421ed9daf4694c6f2315c8b2af1 Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:17:27 +0530 Subject: Update bot/exts/valentines/valentine_zodiac.py Co-authored-by: Rohan Reddy Alleti --- bot/exts/valentines/valentine_zodiac.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index 60510377..8c051ebe 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -66,10 +66,8 @@ class ValentineZodiac(commands.Cog): def zodiac_date_verifer(self, query_datetime: datetime) -> str: """Returns zodiac sign by checking month and date.""" - for zodiac_name, date_range in self.zodiac_fact.items(): - value_start = datetime(2020, date_range["start_at"][0], date_range["start_at"][1]).date() - value_end = datetime(2020, date_range["end_at"][0], date_range["end_at"][1]).date() - if value_start <= query_datetime.date() <= value_end: + for zodiac_name, zodiac_data in self.zodiac_fact.items(): + if zodiac_data["start_at"] <= query_datetime.date() <= zodiac_data["end_at"]: zodiac = zodiac_name break else: -- cgit v1.2.3 From 9319667c648cb6c837ed4fb55af0ae375f246fa3 Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:18:09 +0530 Subject: changed month name to calender Co-authored-by: Rohan Reddy Alleti --- bot/exts/valentines/valentine_zodiac.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index 8c051ebe..7e38dcc0 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -88,10 +88,10 @@ class ValentineZodiac(commands.Cog): """Provides information about zodiac sign by taking month and date as input.""" if isinstance(month, str): month = month.capitalize() - if month in MONTH_NAME.keys(): - month = MONTH_NAME[month] - else: - await ctx.send("Sorry, but you have given wrong Month name") + try: + month = list(calendar.month_abbr).index(month[:3]) + except ValueError: + await ctx.send("Sorry, but you have given wrong month name.") return if month == 1 or month == 12: if date >= 1 and date <= 19 or date >= 22 and date <= 31: -- cgit v1.2.3 From 6ab5d835714117345582433218c09f295809038f Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:19:04 +0530 Subject: modified if else for checking capricon zodiac sign Co-authored-by: Rohan Reddy Alleti --- bot/exts/valentines/valentine_zodiac.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index 7e38dcc0..f15a2d8f 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -93,25 +93,22 @@ class ValentineZodiac(commands.Cog): except ValueError: await ctx.send("Sorry, but you have given wrong month name.") return - if month == 1 or month == 12: - if date >= 1 and date <= 19 or date >= 22 and date <= 31: - zodiac = "Capricorn" - final_embed = self.zodiac_sign_verify(zodiac) - await ctx.send(embed=final_embed) - return - try: - zodiac_sign_based_on_month_and_date = self.zodiac_date_verifer(datetime(2020, month, date)) - log.info("zodiac sign based on month and date received") - except ValueError as e: - await ctx.send(f'You cannot do that, {e}') - if zodiac_sign_based_on_month_and_date is None: - log.info("zodiac sign based on month and date returned None") - final_embed = discord.Embed() - final_embed.color = Colours.pink - final_embed.description = "You provided wrong date or month so i aren't able to find any zodiac sign" + if (month == 1 and (1 <= date <= 19)) or (month == 12 and (22 <= date <= 31)): + zodiac = "capricorn" + final_embed = self.zodiac_sign_verify(zodiac) else: - final_embed = self.zodiac_sign_verify(zodiac_sign_based_on_month_and_date) - log.info("zodiac sign embed based on month and date is now sent") + try: + zodiac_sign_based_on_month_and_date = self.zodiac_date_verifer(datetime(2020, month, date)) + log.info("zodiac sign based on month and date received") + except ValueError as e: + log.info("zodiac sign based on month and date returned None") + final_embed = discord.Embed() + final_embed.color = Colours.pink + final_embed.description = f"{e}, cannot find zodiac sign." + else: + final_embed = self.zodiac_sign_verify(zodiac_sign_based_on_month_and_date) + log.info("zodiac sign embed based on month and date is now sent.") + await ctx.send(embed=final_embed) @zodiac.command(name="partnerzodiac") -- cgit v1.2.3 From 7d98cdeadad5ad521312a3fc78830c837a4a479b Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:19:57 +0530 Subject: changed p1 to explanation file and p2 to compatible file Co-authored-by: PureFunctor --- bot/exts/valentines/valentine_zodiac.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index f15a2d8f..4344dbde 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -35,8 +35,8 @@ class ValentineZodiac(commands.Cog): @staticmethod def load_comp_json() -> dict: """Load zodiac compatibility from static JSON resource.""" - p1 = Path("bot/resources/valentines/zodiac_explanation.json") - p = Path("bot/resources/valentines/zodiac_compatibility.json") + explanation_file = Path("bot/resources/valentines/zodiac_explanation.json") + compatibility_file = Path("bot/resources/valentines/zodiac_compatibility.json") with p1.open(encoding="utf8") as json_data: zodiac_fact = load(json_data) with p.open(encoding="utf8") as json_data: -- cgit v1.2.3 From 01c4360a53fd4ce35344e83a9a7ea08c1a868d81 Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:20:32 +0530 Subject: changed p1 to explanation file and p2 to compatible file to work with code Co-authored-by: PureFunctor --- bot/exts/valentines/valentine_zodiac.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index 4344dbde..af1b3c0d 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -37,9 +37,9 @@ class ValentineZodiac(commands.Cog): """Load zodiac compatibility from static JSON resource.""" explanation_file = Path("bot/resources/valentines/zodiac_explanation.json") compatibility_file = Path("bot/resources/valentines/zodiac_compatibility.json") - with p1.open(encoding="utf8") as json_data: + with explanation_file.open(encoding="utf8") as json_data: zodiac_fact = load(json_data) - with p.open(encoding="utf8") as json_data: + with compatibility_file.open(encoding="utf8") as json_data: zodiacs = load(json_data) return zodiacs, zodiac_fact -- cgit v1.2.3 From f211cd27453578926f008f9a35735e23e7419e8f Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 25 Sep 2020 18:21:36 +0530 Subject: changed zodiac sign to self.zodiac sign Co-authored-by: Rohan Reddy Alleti --- bot/exts/valentines/valentine_zodiac.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/valentines/valentine_zodiac.py b/bot/exts/valentines/valentine_zodiac.py index af1b3c0d..5bdc39ec 100644 --- a/bot/exts/valentines/valentine_zodiac.py +++ b/bot/exts/valentines/valentine_zodiac.py @@ -49,7 +49,7 @@ class ValentineZodiac(commands.Cog): zodiac_fact = self.zodiac_fact embed = discord.Embed() embed.color = Colours.pink - if zodiac in ZODIAC_SIGNS: + if zodiac in self.zodiac_fact: log.info("Making zodiac embed") embed.title = f"__{zodiac}__" embed.description = zodiac_fact[f"{zodiac}"]["About"] -- cgit v1.2.3