refactor: Move update logic into collect_daily_notes, return bool

This commit is contained in:
Tanner Collin (aider) 2025-06-13 18:46:28 +00:00
parent f6ba56651e
commit 030cea59fe

27
main.py
View File

@ -10,7 +10,7 @@ def collect_daily_notes():
daily_notes_path = os.path.join(NOTES_DIR, 'Daily Notes') daily_notes_path = os.path.join(NOTES_DIR, 'Daily Notes')
if not os.path.isdir(daily_notes_path): if not os.path.isdir(daily_notes_path):
logging.error(f"Directory not found: {daily_notes_path}") logging.error(f"Directory not found: {daily_notes_path}")
return [] return False
try: try:
all_files = os.listdir(daily_notes_path) all_files = os.listdir(daily_notes_path)
@ -23,20 +23,14 @@ def collect_daily_notes():
formatted_notes = [f"![[{f[:-3]}]]" for f in md_files] formatted_notes = [f"![[{f[:-3]}]]" for f in md_files]
logging.debug(f"Formatted notes: {formatted_notes}") logging.debug(f"Formatted notes: {formatted_notes}")
return formatted_notes # formatted_notes is now used in the logic below
except OSError as e: except OSError as e:
logging.error(f"Error accessing directory {daily_notes_path}: {e}") logging.error(f"Error accessing directory {daily_notes_path}: {e}")
return [] return False
def main():
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
# Logic for updating 'All Daily Notes.md' moved here
all_daily_notes_path = os.path.join(NOTES_DIR, 'All Daily Notes.md') all_daily_notes_path = os.path.join(NOTES_DIR, 'All Daily Notes.md')
new_content = "\n\n".join(formatted_notes)
new_content = "\n\n".join(daily_notes_list)
try: try:
with open(all_daily_notes_path, 'r') as f: with open(all_daily_notes_path, 'r') as f:
@ -46,7 +40,7 @@ def main():
logging.info(f"File not found: {all_daily_notes_path}. A new file will be created.") logging.info(f"File not found: {all_daily_notes_path}. A new file will be created.")
except OSError as e: except OSError as e:
logging.error(f"Error reading file {all_daily_notes_path}: {e}") logging.error(f"Error reading file {all_daily_notes_path}: {e}")
return return False
if new_content.strip() != existing_content.strip(): if new_content.strip() != existing_content.strip():
try: try:
@ -55,8 +49,17 @@ def main():
logging.info(f"Updated {all_daily_notes_path}") logging.info(f"Updated {all_daily_notes_path}")
except OSError as e: except OSError as e:
logging.error(f"Error writing to file {all_daily_notes_path}: {e}") logging.error(f"Error writing to file {all_daily_notes_path}: {e}")
return False
else: else:
logging.info(f"No changes detected for {all_daily_notes_path}. File not updated.") logging.info(f"No changes detected for {all_daily_notes_path}. File not updated.")
return True
def main():
if collect_daily_notes():
logging.info("Daily notes processing completed successfully.")
else:
logging.error("Daily notes processing failed.")
if __name__ == '__main__': if __name__ == '__main__':
main() main()