Skip to content
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

Add a timestamp to the session start/stop #4

Merged
merged 2 commits into from
Mar 17, 2024
Merged
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ repos:
name: "run mypy"
additional_dependencies:
- "types-requests"
- "types-tzlocal"

- repo: https://github.com/python-poetry/poetry
rev: "1.8.0"
Expand Down
3 changes: 3 additions & 0 deletions fastapi_tui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import locale
import shutil
import signal
import subprocess
Expand Down Expand Up @@ -54,6 +55,8 @@ def __init__(self) -> None:
self.uvicorn_binary = self.get_uvicorn()
self.queue: Queue[str] = Queue()

locale.setlocale(locale.LC_ALL, "")

def action_exit_app(self) -> None:
"""Exit the application.

Expand Down
15 changes: 13 additions & 2 deletions fastapi_tui/threads/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import threading
import time
from datetime import datetime
from queue import Empty, Queue

from tzlocal import get_localzone

from fastapi_tui.log_viewer import LogViewer


Expand All @@ -17,14 +20,16 @@ def __init__(self, log_view: LogViewer, queue: Queue[str]) -> None:
self.stop_event = threading.Event()
self.queue = queue

self.timezone = get_localzone()

def stop(self) -> None:
"""Stop the thread."""
self.stop_event.set()
self.join()

def run(self) -> None:
"""Run the thread."""
self.log_view.add("[blue]Session Started\n")
self.log_view.add(f"[blue]Session Started @ {self.get_local_time()}\n")
while not self.stop_event.is_set():
try:
line = self.queue.get_nowait()
Expand All @@ -33,4 +38,10 @@ def run(self) -> None:
else:
self.log_view.add(line.strip())

self.log_view.add("\n[blue]Session Closed")
self.log_view.add(f"\n[blue]Session Closed @ {self.get_local_time()}")

def get_local_time(self) -> str:
"""Return the current time in the local timezone."""
return (
datetime.now(self.timezone).replace(microsecond=0).strftime("%X %x")
)
57 changes: 55 additions & 2 deletions poetry.lock

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

8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fastapi-tui = "fastapi_tui.main:app"
python = ">=3.9,<4.0"
fastapi = { extras = ["all"], version = "^0.110.0" }
textual = "^0.52.1"
tzlocal = "^5.2"

[build-system]
requires = ["poetry-core"]
Expand Down Expand Up @@ -67,8 +68,13 @@ mkdocstrings = ">=0.24.1"
pymdown-extensions = "^10.7"
pygments = "^2.17.2"

# setup PoeThePoet tasks
# textual debugging
textual-dev = "^1.5.1"

# for type-checking
types-tzlocal = "^5.1.0.1"

# setup PoeThePoet tasks
[tool.poe.tasks]
pre.cmd = "pre-commit run --all-files"
pre.help = "Run pre-commit checks"
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ textual==0.52.1 ; python_version >= "3.9" and python_version < "4.0"
tomli==2.0.1 ; python_version >= "3.9" and python_version < "4.0"
toolz==0.12.1 ; python_version >= "3.9" and python_version < "4.0"
typer==0.9.0 ; python_version >= "3.9" and python_version < "4.0"
types-pytz==2024.1.0.20240203 ; python_version >= "3.9" and python_version < "4.0"
types-tzlocal==5.1.0.1 ; python_version >= "3.9" and python_version < "4.0"
typing-extensions==4.10.0 ; python_version >= "3.9" and python_version < "4.0"
tzdata==2024.1 ; python_version >= "3.9" and python_version < "4.0" and platform_system == "Windows"
tzlocal==5.2 ; python_version >= "3.9" and python_version < "4.0"
uc-micro-py==1.0.3 ; python_version >= "3.9" and python_version < "4.0"
ujson==5.9.0 ; python_version >= "3.9" and python_version < "4.0"
urllib3==2.2.1 ; python_version >= "3.9" and python_version < "4.0"
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ sniffio==1.3.1 ; python_version >= "3.9" and python_version < "4.0"
starlette==0.36.3 ; python_version >= "3.9" and python_version < "4.0"
textual==0.52.1 ; python_version >= "3.9" and python_version < "4.0"
typing-extensions==4.10.0 ; python_version >= "3.9" and python_version < "4.0"
tzdata==2024.1 ; python_version >= "3.9" and python_version < "4.0" and platform_system == "Windows"
tzlocal==5.2 ; python_version >= "3.9" and python_version < "4.0"
uc-micro-py==1.0.3 ; python_version >= "3.9" and python_version < "4.0"
ujson==5.9.0 ; python_version >= "3.9" and python_version < "4.0"
uvicorn[standard]==0.28.0 ; python_version >= "3.9" and python_version < "4.0"
Expand Down