no blinking on the dashboard

This commit is contained in:
2025-10-13 13:26:34 +02:00
parent 5800fb6e2c
commit ad4cf07585
3 changed files with 118 additions and 100 deletions

View File

@ -25,10 +25,11 @@ STATUS_FILE = os.path.join("_data", "fetcher_status.json")
def run_market_feeder():
"""Target function to run the market.py script in a separate process."""
setup_logging('normal', 'MarketFeedProcess')
setup_logging('off', 'MarketFeedProcess')
logging.info("Market feeder process started.")
try:
subprocess.run([sys.executable, MARKET_FEEDER_SCRIPT], check=True)
# Pass the log level to the script
subprocess.run([sys.executable, MARKET_FEEDER_SCRIPT, "--log-level", "off"], check=True)
except subprocess.CalledProcessError as e:
logging.error(f"Market feeder script failed with error: {e}")
except KeyboardInterrupt:
@ -48,7 +49,7 @@ def run_data_fetcher_job():
def data_fetcher_scheduler():
"""Schedules and runs the data_fetcher.py script periodically."""
setup_logging('normal', 'DataFetcherScheduler')
setup_logging('off', 'DataFetcherScheduler')
run_data_fetcher_job()
schedule.every(1).minutes.do(run_data_fetcher_job)
logging.info("Data fetcher scheduled to run every 1 minute.")
@ -71,7 +72,7 @@ def run_resampler_job():
def resampler_scheduler():
"""Schedules and runs the resampler.py script periodically."""
setup_logging('normal', 'ResamplerScheduler')
setup_logging('off', 'ResamplerScheduler')
run_resampler_job()
schedule.every(4).minutes.do(run_resampler_job)
logging.info("Resampler scheduled to run every 4 minutes.")
@ -85,6 +86,7 @@ class MainApp:
self.watched_coins = coins_to_watch
self.prices = {}
self.last_db_update_info = "Initializing..."
self._lines_printed = 0 # To track how many lines we printed last time
def read_prices(self):
"""Reads the latest prices from the JSON file."""
@ -122,19 +124,32 @@ class MainApp:
logging.error(f"Could not read status file: {e}")
def display_dashboard(self):
"""Displays a formatted table for prices and DB status."""
print("\x1b[H\x1b[J", end="")
"""Displays a formatted table for prices and DB status without blinking."""
# Move the cursor up to overwrite the previous output
if self._lines_printed > 0:
print(f"\x1b[{self._lines_printed}A", end="")
print("--- Market Dashboard ---")
# Build the output as a single string
output_lines = []
output_lines.append("--- Market Dashboard ---")
table_width = 26
print("-" * table_width)
print(f"{'#':<2} | {'Coin':<6} | {'Live Price':>10} |")
print("-" * table_width)
output_lines.append("-" * table_width)
output_lines.append(f"{'#':<2} | {'Coin':<6} | {'Live Price':>10} |")
output_lines.append("-" * table_width)
for i, coin in enumerate(self.watched_coins, 1):
price = self.prices.get(coin, "Loading...")
print(f"{i:<2} | {coin:<6} | {price:>10} |")
print("-" * table_width)
print(f"DB Status: Last coin updated -> {self.last_db_update_info}")
output_lines.append(f"{i:<2} | {coin:<6} | {price:>10} |")
output_lines.append("-" * table_width)
output_lines.append(f"DB Status: Last coin updated -> {self.last_db_update_info}")
# Join lines and add a code to clear from cursor to end of screen
# This prevents artifacts if the new output is shorter than the old one.
final_output = "\n".join(output_lines) + "\n\x1b[J"
print(final_output, end="")
# Store the number of lines printed for the next iteration
self._lines_printed = len(output_lines)
sys.stdout.flush()
def run(self):