refactor: Move update logic into collect_daily_notes, return bool
This commit is contained in:
parent
f6ba56651e
commit
030cea59fe
27
main.py
27
main.py
|
@ -10,7 +10,7 @@ def collect_daily_notes():
|
|||
daily_notes_path = os.path.join(NOTES_DIR, 'Daily Notes')
|
||||
if not os.path.isdir(daily_notes_path):
|
||||
logging.error(f"Directory not found: {daily_notes_path}")
|
||||
return []
|
||||
return False
|
||||
|
||||
try:
|
||||
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]
|
||||
|
||||
logging.debug(f"Formatted notes: {formatted_notes}")
|
||||
return formatted_notes
|
||||
# formatted_notes is now used in the logic below
|
||||
except OSError as e:
|
||||
logging.error(f"Error accessing directory {daily_notes_path}: {e}")
|
||||
return []
|
||||
|
||||
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
|
||||
return False
|
||||
|
||||
# Logic for updating 'All Daily Notes.md' moved here
|
||||
all_daily_notes_path = os.path.join(NOTES_DIR, 'All Daily Notes.md')
|
||||
|
||||
new_content = "\n\n".join(daily_notes_list)
|
||||
new_content = "\n\n".join(formatted_notes)
|
||||
|
||||
try:
|
||||
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.")
|
||||
except OSError as e:
|
||||
logging.error(f"Error reading file {all_daily_notes_path}: {e}")
|
||||
return
|
||||
return False
|
||||
|
||||
if new_content.strip() != existing_content.strip():
|
||||
try:
|
||||
|
@ -55,8 +49,17 @@ def main():
|
|||
logging.info(f"Updated {all_daily_notes_path}")
|
||||
except OSError as e:
|
||||
logging.error(f"Error writing to file {all_daily_notes_path}: {e}")
|
||||
return False
|
||||
else:
|
||||
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__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user