Skip to content

Commit

Permalink
Merge branch 'main' into feat_avg_buy_price
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed May 5, 2024
2 parents e88f57d + b5d0b67 commit 0c12789
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
43 changes: 42 additions & 1 deletion poetry.lock

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

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tinyticker"
version = "0.4.12"
version = "0.5.0"
description = "A tiny Raspberry Pi powered ePaper ticker."
authors = ["Loic Coyle <[email protected]>"]
license = "MIT"
Expand All @@ -22,6 +22,7 @@ yfinance = "^0.2.0"
qrcode = "^7.3.1"
packaging = "^23.0"
numpy = "^1.26"
watchdog = "^4.0.0"

[tool.poetry.scripts]
tinyticker = 'tinyticker.__main__:main'
Expand Down
2 changes: 1 addition & 1 deletion tinyticker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

logger.addHandler(logging.NullHandler())

__version__ = "0.4.12"
__version__ = "0.5.0"
__all__ = ["Display", "Ticker"]
26 changes: 23 additions & 3 deletions tinyticker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from time import sleep
from typing import List

from watchdog.events import FileModifiedEvent, FileSystemEventHandler
from watchdog.observers import Observer

from . import __version__, logger
from .config import TinytickerConfig
from .display import Display
Expand Down Expand Up @@ -155,9 +158,22 @@ def restart(*_) -> None:
def refresh(*_) -> None:
"""Kill the ticker process, it gets restarted in the main thread."""
logger.info("Refreshing ticker process.")
tick_process.kill()
tick_process.join()
tick_process.close()
if not tick_process._closed and tick_process.is_alive(): # type: ignore
tick_process.kill()
tick_process.join()
tick_process.close()

class ConfigModifiedHandler(FileSystemEventHandler):
def on_modified(self, event):
logger.info(f"{event.src_path} was changed, refreshing ticker thread.")
refresh()

observer = Observer()
config_modified_handler = ConfigModifiedHandler()
observer.schedule(
config_modified_handler, config_file, event_filter=[FileModifiedEvent]
)
observer.start()

signal.signal(signal.SIGUSR2, refresh)

Expand All @@ -166,6 +182,10 @@ def cleanup():
logger.info("Exiting.")
if PID_FILE.is_file():
PID_FILE.unlink()
observer.stop()
observer.join()
tick_process.kill()
tick_process.join()

atexit.register(cleanup)

Expand Down
3 changes: 1 addition & 2 deletions tinyticker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def check_for_update(current_version: str, **kwargs) -> bool:
def now() -> pd.Timestamp:
"""Return the current timestamp."""
return pd.to_datetime("now", utc=True)
# return datetime.now(timezone.utc)


def set_verbosity(logger: logging.Logger, verbosity: int) -> logging.Logger:
Expand All @@ -91,7 +90,7 @@ def set_verbosity(logger: logging.Logger, verbosity: int) -> logging.Logger:
verbosity: verbosity level, 1, or 2.
Return:
The `logger` object with configured verbosity.
The `logging.Logger` object with configured verbosity.
"""
verbose_map = {1: logging.INFO, 2: logging.DEBUG}
level = verbose_map[verbosity]
Expand Down
7 changes: 4 additions & 3 deletions tinyticker/web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..ticker import INTERVAL_LOOKBACKS, INTERVAL_TIMEDELTAS, SYMBOL_TYPES
from ..utils import check_for_update
from ..waveshare_lib.models import MODELS
from .command import COMMANDS, reboot, refresh
from .command import COMMANDS, reboot

LOGGER = logging.getLogger(__name__)
TEMPLATE_PATH = str(Path(__file__).parent / "templates")
Expand Down Expand Up @@ -120,7 +120,7 @@ def config():

sequence = SequenceConfig(
skip_outdated=request.args.get("skip_outdated", False, type=bool),
# Note: currently not toggleable from the web app
# NOTE: currently not toggleable from the web app
skip_empty=request.args.get("skip_empty", True, type=bool),
)

Expand All @@ -136,8 +136,9 @@ def config():
sequence=sequence,
)
LOGGER.debug(tt_config)
# writing the config to file, the main ticker process is monitoring this file
# and will refresh the ticker process
tt_config.to_file(config_file)
refresh()
return redirect("/", code=302)

@app.route("/command")
Expand Down
2 changes: 1 addition & 1 deletion tinyticker/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ <h4>Tickers</h4>
id="skip_outdated"
name="skip_outdated"
{% if sequence.skip_outdated | default(True) %}checked{% endif %}
/>Skip tickers with oudated data</label
/>Skip tickers with outdated data</label
>
<button
type="submit"
Expand Down

0 comments on commit 0c12789

Please sign in to comment.