-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery Starbot ⭐ refactored NicolasFlandrois/Stardate #2
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,78 +21,83 @@ 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 | ||
Comment on lines
-42
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
|
||
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): | ||
Comment on lines
-64
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
""" | ||
Stardate calculator | ||
t = Time (cf 'datetime.datetime.now().timetuple()' format) | ||
Compute.config()["earthdate"] = Earthdate Year reference point | ||
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): | ||
Comment on lines
-78
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
""" | ||
Stardate translator | ||
sd = Stardate Time (cf float, stardate format) | ||
Compute.config()["earthdate"] = Earthdate Year reference point | ||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ def clean(): | |
""" | ||
os.system("cls" if platform.system() == "Windows" else "clear") | ||
|
||
def menu(convert, translate): | ||
def menu(self, translate): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
"""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) | ||
) | ||
] | ||
Comment on lines
-73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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] | ||
Comment on lines
-101
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def show_stardate(stardate, date): | ||
def show_stardate(self, date): | ||
""" | ||
Displays Date's Stardate. | ||
""" | ||
print("Earthdate : ", date) | ||
print("\nStardate : ", stardate) | ||
print("\nStardate : ", self) | ||
Comment on lines
-107
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def show_today_stardate(): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
Compute.ask_integer
refactored with the following changes:self
(instance-method-first-arg-name
)remove-unreachable-code
)