Skip to content

Instantly share code, notes, and snippets.

@linuxdotexe
Created August 18, 2023 06:32
Show Gist options
  • Save linuxdotexe/312e9de1a1b1508cd5303c7bae59c0a9 to your computer and use it in GitHub Desktop.
Save linuxdotexe/312e9de1a1b1508cd5303c7bae59c0a9 to your computer and use it in GitHub Desktop.
"""
Author(s): Sai Nivas Mangu
Description: A program to move old TODO files into "Past" folder. I
make TODO lists in my Obsidian daily notes and I felt I was
cluttering the explore pane so I decided to do this. Using the shell
command plugin to run it on Obsidian open, close and file creation.
Suggestions for optimization are very much welcome.
"""
# os for dealing operations on directories.
import os
# datetime to get the date, since the files are named after the date
from datetime import date
# Path locations of where the notes currently are and where I want
# them to be.
src_path = "A://content/EEAAO/Daily Notes/"
dest_path = "A://content/EEAAO/Daily Notes/Past"
# List of files in the source path, filtered by only markdown files.
fileList = [f for f in os.listdir(src_path) if f.endswith(".md")]
# Print statement from when I was testing. Kept alive for future.
# print(fileList)
# Gets the current date in my required format i.e., YYYY-MM-DD
current_date = date.today()
# Made the date into a list since the DD part will need updating.
date_checker = str(current_date).split("-")
# This is made like this to facilitate updates.
current_file = "-".join(date_checker) + ".md"
# A for loop to check the list of files in the source directory
# and move the old files into the Past directory.
# NOTE: I found out while testing the code that I'm a lazy bum.
# I am not finishing the tasks I give myself in the time I give
# myself so I'm using one "daily" note for multiple days. So,
# the `+5` gives me 5 spare days to finish the slack before it
# throws an ugly error.
for i in range(len(fileList)+5):
# This is where the updating happens.
current_file = "-".join(date_checker) + ".md"
# Preserved for debugging purposes.
# print(current_file)
# This checks what date I am on.
if (current_file) in fileList:
break
# If the current date is not the date, it decrements the date.
date_checker[2] = str(int(date_checker[2]) - 1)
# print(current_file)
# And the file that is current, is removed from the list.
fileList.remove(current_file)
# The rest of the files in the list are moved to the Past folder.
for file in fileList:
src = os.path.join(src_path, file)
dest = os.path.join(dest_path, file)
os.rename(src, dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment