From 7c4d4819af2c5881155d2a713100ccb288a8c7f4 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@arch-desktop" Date: Tue, 19 May 2020 10:01:00 +0200 Subject: [PATCH] Set last_seen file in .cache folder --- dotfiles/i3/scripts/arch_linux_news/arch_linux_news | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dotfiles/i3/scripts/arch_linux_news/arch_linux_news b/dotfiles/i3/scripts/arch_linux_news/arch_linux_news index e7aa002..31e17c0 100755 --- a/dotfiles/i3/scripts/arch_linux_news/arch_linux_news +++ b/dotfiles/i3/scripts/arch_linux_news/arch_linux_news @@ -13,11 +13,14 @@ import feedparser # type: ignore def main() -> None: """Parse the rss feed.""" + last_seen_file_path = os.path.expanduser("~/.cache/arch_linux_news_last_seen") + try: - with open("last_seen", "r") as last_seen_file: + with open(last_seen_file_path, "r") as last_seen_file: last_seen = last_seen_file.read().strip() except FileNotFoundError: - pass + with open(last_seen_file_path, "w") as last_seen_file: + last_seen_file.write("") url = "https://www.archlinux.org/feeds/news/" feed = feedparser.parse(url) @@ -27,13 +30,15 @@ def main() -> None: if os.environ.get("BLOCK_BUTTON", "") == "1": last_seen = feed["entries"][0]["published"] - with open("last_seen", "w") as last_seen_file: + with open(last_seen_file_path, "w") as last_seen_file: last_seen_file.write(last_seen) subprocess.run(f"xdg-open {latest_link}", shell=True, check=True) if feed["entries"][0]["published"] != last_seen: print(latest_title) + else: + print("Arch Linux news is up to date") if __name__ == "__main__":