Created
May 13, 2023 19:51
-
-
Save tylersnowden/773f44c8cc884149a79edabc5d22781f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date, timedelta | |
import os | |
def main(): | |
# Get Today's Date in YYYY-MM-DD Format | |
today = date.today() | |
# Is Today Friday, Saturday or Sunday? | |
if today.weekday() == 4 or today.weekday() == 5 or today.weekday() == 6: | |
if today.weekday() > 4: | |
# Get Last Friday | |
while today.weekday() != 4: | |
today = today - timedelta(days=1) | |
# Get Next Monday | |
tomorrow = today | |
while tomorrow.weekday() != 0: | |
tomorrow = tomorrow + timedelta(days=1) | |
else: | |
tomorrow = today + timedelta(days=1) | |
today_str = today.strftime('%Y-%m-%d') | |
tomorrow_str = tomorrow.strftime('%Y-%m-%d') | |
today_week = today.isocalendar()[1] | |
today_year = today.isocalendar()[0] | |
today_file_path = str(today_year) + ' Daily/Week ' + str(today_week) + '/' | |
tomorrow_week = tomorrow.isocalendar()[1] | |
tomorrow_year = tomorrow.isocalendar()[0] | |
tomorrow_file_path = str(tomorrow_year) + ' Daily/Week ' + str(tomorrow_week) + '/' | |
# If tomorrow directory does not exist, create it | |
if not os.path.exists(tomorrow_file_path): | |
os.makedirs(tomorrow_file_path) | |
today_file = today_file_path + today_str + '.md' | |
tomorrow_file = tomorrow_file_path + tomorrow_str + '.md' | |
with open(today_file, 'r') as todo: | |
migrated_todos = [] | |
lines = todo.readlines() | |
for line in lines: | |
# Unfinished Task | |
if line.find('[ ]') != -1: | |
migrated_todos.append(line) | |
with open(today_file, 'r') as todo: | |
# Mark unfinished tasks as migrated | |
data = todo.read() | |
data = data.replace('[ ]', '[>]') | |
# Update ToDo List for Today | |
with open(today_file, 'w') as todo: | |
todo.write(data) | |
# Append Migrated ToDo List to Tomorrow's ToDo List | |
with open(tomorrow_file, 'a') as todo2: | |
todo2.writelines(migrated_todos) | |
print("Migrated ToDo List for " + today_str + ".") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment