Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions nmr/scripts/clock.py
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(
Copy link
Owner

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:

  1. Splitting time into numbers
  2. Independently converting each number to a name
  3. Printing it

But this gives the same name to the same time each day - and it isn't actually dealing with any of the issues.

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():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were using textual, this wouldn't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intermediate variables don't help here.

Also, it's "time"!

return datetime.now().strftime(TIME_FORMAT), where TIME_FORMAT is some constant at the top of the file.

"""Gets the current tume"""
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
return current_time


def splitTimeString(timeStr: list):
Copy link
Owner

Choose a reason for hiding this comment

The 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 str, and what's with all the mixEdCaseStuff, this isn't Java!

"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.")
102 changes: 98 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ lat-lon-parser = "^1.3.0"
typer = "^0.7.0"
chess = "^1.9.3"
semver = "^3.0.2"
rich = "^14.0.0"

[tool.poetry.group.dev.dependencies]
coverage = "^6.5.0"
Expand Down