diff --git a/main.py b/main.py index 1066468..2ac35d5 100644 --- a/main.py +++ b/main.py @@ -29,7 +29,34 @@ def collect_daily_notes(): return [] def main(): - collect_daily_notes() + daily_notes_list = collect_daily_notes() + if not daily_notes_list: + logging.info("No daily notes found or an error occurred. Skipping update of 'All Daily Notes.md'.") + return + + all_daily_notes_path = os.path.join(NOTES_DIR, 'All Daily Notes.md') + + new_content = "\n\n".join(daily_notes_list) + + try: + with open(all_daily_notes_path, 'r') as f: + existing_content = f.read() + except FileNotFoundError: + existing_content = "" + logging.info(f"File not found: {all_daily_notes_path}. A new file will be created.") + except OSError as e: + logging.error(f"Error reading file {all_daily_notes_path}: {e}") + return + + if new_content.strip() != existing_content.strip(): + try: + with open(all_daily_notes_path, 'w') as f: + f.write(new_content) + logging.info(f"Updated {all_daily_notes_path}") + except OSError as e: + logging.error(f"Error writing to file {all_daily_notes_path}: {e}") + else: + logging.info(f"No changes detected for {all_daily_notes_path}. File not updated.") if __name__ == '__main__': main()