From d5a3b15f88f78e4f8d123195f0599032b839ed5c Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Fri, 2 Dec 2022 00:47:15 +0000 Subject: [PATCH] Created day-selector.py to automatically open python file for current day --- day-selector.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 day-selector.py diff --git a/day-selector.py b/day-selector.py new file mode 100644 index 0000000..2f9792e --- /dev/null +++ b/day-selector.py @@ -0,0 +1,22 @@ +import os +from datetime import date + + +def main(): + currentDay = date.today().day + reposDirectory = f"/home/{os.getlogin()}/repos/advent-of-code-2022/" + dayGroups = [(int(days[4:].split('-')[0]), int(days[4:].split('-')[1])) for days in [directory for directory in os.listdir(reposDirectory) if directory.startswith('days')][::-1]] + indexOfDayGroup = -1 + for dayGroup in dayGroups: + if dayGroup[0] < currentDay < dayGroup[1]: + indexOfDayGroup = dayGroups.index(dayGroup) + break + currentDayGroupDir = f"{reposDirectory}/days{dayGroups[indexOfDayGroup][0]}-{dayGroups[indexOfDayGroup][1]}" + currentDayDir = f"{currentDayGroupDir}/day{currentDay}" + if f"day{currentDay}" not in os.listdir(currentDayGroupDir): + os.system(f"mkdir {currentDayDir}") + os.system(f"vim {currentDayDir}/day{currentDay}.py") + + +if __name__ == "__main__": + main()