From 30b498843189efc380277a5a03d7195e098dcae5 Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Sat, 11 Nov 2023 17:28:12 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- sdcompute.py | 63 ++++++++++++++++++++++++++++------------------------ sdview.py | 59 ++++++++++++++++++++++++------------------------ 2 files changed, 64 insertions(+), 58 deletions(-) diff --git a/sdcompute.py b/sdcompute.py index 68a0af4..4e46000 100644 --- a/sdcompute.py +++ b/sdcompute.py @@ -21,47 +21,37 @@ def config(): with open("sdconfig.json") as f: return json.load(f) - def ask_integer(message: str, range, error_message: str = ""): + def ask_integer(self, range, error_message: str = ""): """ This function's purpose is to ask and verify an Integer. """ var = None while True: try: - var = int(input(message)) + var = int(input(self)) if var in range: return var - raise - except KeyboardInterrupt: break except: print(error_message) - def leapyr(year: int): + def leapyr(self): """" This function defines if the year is a Leap year (366 days) or a Normal year (365 days). Then it will to the variable n the value of 366 or 365, accordingly. """ - if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0): - n = 366 - # print("The year is a Leap year.\n") - - else: - n = 365 - # print("The year is a normal year.\n") - - return n + return 366 if self % 400 == 0 or self % 4 == 0 and self % 100 != 0 else 365 def nowearthdate(): """Will generate automaticaly a tuple datetime object, for now time""" nowdate = datetime.datetime.now() return nowdate.timetuple(), nowdate.strftime('%A, %Y %B %d. %H:%M:%S') - def sdconvert(t): + def sdconvert(self): """ Stardate calculator t = Time (cf 'datetime.datetime.now().timetuple()' format) @@ -69,13 +59,25 @@ def sdconvert(t): Compute.config()["stardate"] = Stardate Yaer reference point Compute.leapyr(t.tm_year) = number of days leap year/not (365 or 366) """ - return format(((Compute.config()["stardate"] + - (1000*(t.tm_year - Compute.config()["earthdate"]))) + - ((1000/((Compute.leapyr(t.tm_year))*1440.0))*((( - t.tm_yday - 1.0)*1440.0) + - (t.tm_hour*60.0) + t.tm_min))), '.2f') + return format( + ( + Compute.config()["stardate"] + + 1000 * (self.tm_year - Compute.config()["earthdate"]) + ) + + ( + 1000 + / (Compute.leapyr(self.tm_year) * 1440.0) + * ( + ( + (((self.tm_yday - 1.0) * 1440.0) + self.tm_hour * 60.0) + + self.tm_min + ) + ) + ), + '.2f', + ) - def sdtranslate(sd): + def sdtranslate(self): """ Stardate translator sd = Stardate Time (cf float, stardate format) @@ -83,16 +85,19 @@ def sdtranslate(sd): Compute.config()["stardate"] = Stardate Yaer reference point Compute.leapyr(t.tm_year) = number of days leap year/not (365 or 366) """ - print("Stardate : ", sd) + print("Stardate : ", self) - dlist = [] - ed_year = int(((sd - Compute.config()["stardate"]) // 1000) + - Compute.config()["earthdate"]) - dlist.append(int(ed_year)) - ed_time = (((sd - Compute.config()["stardate"]) % 1000) / - (1000 / (1440*Compute.leapyr(ed_year)))) + ed_year = int( + (self - Compute.config()["stardate"]) // 1000 + + Compute.config()["earthdate"] + ) + ed_time = ( + (self - Compute.config()["stardate"]) + % 1000 + / (1000 / (1440 * Compute.leapyr(ed_year))) + ) ed_day = (ed_time//1440)+1 - dlist.append(int(ed_day)) + dlist = [ed_year, int(ed_day)] ed_hour = (ed_time-((ed_day-1)*1440))//60 dlist.append(int(ed_hour)) ed_min = ed_time % 60 diff --git a/sdview.py b/sdview.py index 1013f35..5589a20 100644 --- a/sdview.py +++ b/sdview.py @@ -23,7 +23,7 @@ def clean(): """ os.system("cls" if platform.system() == "Windows" else "clear") - def menu(convert, translate): + def menu(self, translate): """menu docstring""" View.clean() print("STARDATE\n") @@ -40,27 +40,26 @@ def menu(convert, translate): View.clean() try: - if responce.strip().lower() in ['r', 'q', '1', '2', '3']: - if responce.strip().lower() == 'r': - continue - elif responce.strip().lower() == 'q': - break - elif responce.strip().lower() == '1': - View.clean() - View.show_today_stardate() - print('\n') - elif responce.strip().lower() == '2': - View.clean() - date = View.ask_date() - stardate = Compute.sdconvert(date[0]) - View.show_stardate(stardate, date[1]) - print('\n') - elif responce.strip().lower() == '3': - View.clean() - print("\nEarthdate : ", translate(View.ask_stardate())) - print('\n') - else: - raise + if responce.strip().lower() not in ['r', 'q', '1', '2', '3']: + raise + if responce.strip().lower() == 'r': + continue + elif responce.strip().lower() == 'q': + break + elif responce.strip().lower() == '1': + View.clean() + View.show_today_stardate() + print('\n') + elif responce.strip().lower() == '2': + View.clean() + date = View.ask_date() + stardate = Compute.sdconvert(date[0]) + View.show_stardate(stardate, date[1]) + print('\n') + elif responce.strip().lower() == '3': + View.clean() + print("\nEarthdate : ", translate(View.ask_stardate())) + print('\n') else: raise except: @@ -70,9 +69,11 @@ def ask_date(): """ Ask input and return for the date object. """ - dlist = [] - dlist.append(Compute.ask_integer("Earth Year? (YYYY format) ", - range(-10000000, 10000000))) + dlist = [ + Compute.ask_integer( + "Earth Year? (YYYY format) ", range(-10000000, 10000000) + ) + ] dlist.append(Compute.ask_integer("Earth Month? (from 01 to 12) ", range(1, 13))) dlist.append(Compute.ask_integer("Day of the month? (from 01 to 31) ", @@ -98,18 +99,18 @@ def ask_stardate(): View.clean() return stardate - def show_date(earthdate): + def show_date(self): """ Displays a date object, in a User Experience readable format. """ - return earthdate()[1] + return self()[1] - def show_stardate(stardate, date): + def show_stardate(self, date): """ Displays Date's Stardate. """ print("Earthdate : ", date) - print("\nStardate : ", stardate) + print("\nStardate : ", self) def show_today_stardate(): """