-
-
Notifications
You must be signed in to change notification settings - Fork 1
introduced v1 of nmr clock #19
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
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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| from rich import print | ||
| from nmr import nmr | ||
| from datetime import datetime | ||
| import time | ||
| import os | ||
| import sys | ||
|
|
||
|
|
||
| def main(): | ||
| """Generates nmr clock output""" | ||
| clear_terminal() | ||
| while True: | ||
| raw_time_string = getCurrentTime() | ||
| [hour, minute, second] = [nmr.str_to_name( | ||
| i) for i in splitTimeString(raw_time_string)] | ||
| printer(f"{hour}:{minute}:{second}") | ||
| # Introduce delay by a second to avoid millisecond flicker | ||
| time.sleep(1) | ||
|
|
||
|
|
||
| def clear_terminal(): | ||
|
Owner
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. If you were using
Contributor
Author
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. Oh, thanks a bunch! |
||
| """Clears the terminal screen.""" | ||
| os.system('cls' if os.name == 'nt' else 'clear') | ||
|
|
||
|
|
||
| def printer(time_item): | ||
| """Handles printing of the output""" | ||
| # Overwrite line with spaces that are the length of terminal size for cleaning | ||
| clean_line = f"\r{' ' * os.get_terminal_size().columns}\r" | ||
| # Use rich markup and write to stdout manually | ||
| sys.stdout.write(clean_line) | ||
| print( | ||
| f"[bold magenta]{time_item}[/bold magenta]", end="") | ||
| sys.stdout.flush() | ||
|
|
||
|
|
||
| def getCurrentTime(): | ||
|
Owner
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. The intermediate variables don't help here. Also, it's "time"!
|
||
| """Gets the current tume""" | ||
| now = datetime.now() | ||
| current_time = now.strftime("%H:%M:%S") | ||
| return current_time | ||
|
|
||
|
|
||
| def splitTimeString(timeStr: list): | ||
|
Owner
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. This is much too short to be a function. Also, the type isn't right, it should be |
||
| "Splits the time string into a list of [HH, MM, SS]" | ||
| new_string_list = timeStr.split(sep=":") | ||
| return new_string_list | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| main() | ||
| except KeyboardInterrupt: | ||
| print("\nClock stopped.") | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
So this doesn't actually work.
What you are actually doing is this:
But this gives the same name to the same time each day - and it isn't actually dealing with any of the issues.