From 46a8e7d1d6ad459c78616c9ac076d30b09fb87c8 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sat, 5 Oct 2024 20:19:14 +0100 Subject: have sisyphus print the number of unread news during sync --- src/backend/checkenv.py | 10 ++++++++++ src/backend/getnews.py | 14 +------------- src/backend/syncall.py | 10 ++++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/backend') diff --git a/src/backend/checkenv.py b/src/backend/checkenv.py index 124ba76..4f540e9 100644 --- a/src/backend/checkenv.py +++ b/src/backend/checkenv.py @@ -3,6 +3,7 @@ import os import subprocess import sisyphus.getenv +import sisyphus.getnews import urllib.request @@ -22,6 +23,15 @@ def root(): return True if os.getuid() == 0 else False +def news(): + n_news = sisyphus.getnews.ld_n_news() + r_news_index = sisyphus.getnews.ld_r_news() + + unread_count = len(n_news) - len(r_news_index) + + return unread_count + + def sanity(): actv_brch = sisyphus.getenv.sys_brch() bhst_addr = sisyphus.getenv.bhst_addr() diff --git a/src/backend/getnews.py b/src/backend/getnews.py index b2d2978..cce7bcb 100644 --- a/src/backend/getnews.py +++ b/src/backend/getnews.py @@ -84,19 +84,7 @@ def list_all_news(): f"\nArticle {sisyphus.getclr.green}{index + 1}{sisyphus.getclr.reset} ({status}):\n{news}") -def check_n_news(): - n_news = ld_n_news() - r_news_index = ld_r_news() - - unread_count = len(n_news) - len(r_news_index) - - return unread_count - - -def start(check=False, list=False, read=False, unread=False, article_nr=None): - if check: - check_n_news() - +def start(list=False, read=False, unread=False, article_nr=None): if list: list_all_news() diff --git a/src/backend/syncall.py b/src/backend/syncall.py index 5cbcd8f..ac53d13 100644 --- a/src/backend/syncall.py +++ b/src/backend/syncall.py @@ -32,6 +32,7 @@ def start(gfx_ui=False): bhst_addr = sisyphus.getenv.bhst_addr() is_sane = sisyphus.checkenv.sanity() is_online = sisyphus.checkenv.connectivity() + unread_count = sisyphus.checkenv.news() if is_online != 1: if gfx_ui: @@ -48,6 +49,15 @@ def start(gfx_ui=False): else: if is_sane == 1: sync_evrth() + if gfx_ui: + print(f"\n\nThere are {unread_count} unread news article(s).") + else: + if unread_count > 0: + print( + f"\n\nThere are {sisyphus.getclr.bright_red}{unread_count}{sisyphus.getclr.reset} unread news article(s).") + else: + print( + f"\n\nThere are {sisyphus.getclr.green}{unread_count}{sisyphus.getclr.reset} unread news article(s).") else: if gfx_ui: if "packages-next" in bhst_addr: -- cgit v1.2.3