From d042a7c84086032c1dbd4441f584b317d896a166 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 20 May 2024 22:32:12 +0100 Subject: [PATCH] fixed last transcript detection --- .gitignore | 1 + config/last | 0 spaceweather.py | 23 ++++++++++++++--------- testfile | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) mode change 100755 => 100644 config/last create mode 100644 testfile diff --git a/.gitignore b/.gitignore index 41833bf..8a6f8dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/config/last /spaceweather.wav /spaceweather.mp3 /media/graph* diff --git a/config/last b/config/last old mode 100755 new mode 100644 diff --git a/spaceweather.py b/spaceweather.py index ec5f1aa..0053de4 100755 --- a/spaceweather.py +++ b/spaceweather.py @@ -192,15 +192,20 @@ transcript = generate_transcript() text = "\n".join(transcript) # check the last generated transcript -with open("config/last", "r") as f: - last = f.read() - -# quit if the transcript is the same as the last -if last == text: - print("no change!") - quit() -else: - print("proceeding...") +try: + with open("config/last", "r") as f: + last = f.read() + + # quit if the transcript is the same as the last + if last == text: + print("no change!") + quit() + else: + print("New spaceweather issued!") +except FileNotFoundError: + print("no previous spaceweather detected!") + +print("Generating new spaceweather...") # write the raw transcript to a file with open("config/last", "w") as f: f.write(text) diff --git a/testfile b/testfile new file mode 100644 index 0000000..a8d8fd2 --- /dev/null +++ b/testfile @@ -0,0 +1 @@ +testing! -- 2.39.2