I have googled and googled and I can't find anything that works. I need to grab the date within the name of the file, turn it into the julian date, and then, rename the original file so that it also includes the julian date.
for file in os.listdir("/home/mydir/"):
if file.startswith("awesome"):
awesome_file = file.split(' ')
awesome_date = awesome_file[2]
awesome_year = awesome_date.split()
awesome_year = awesome_date[0] + awesome_date[1] + awesome_date[2] + awesome_date[3]
awesome_month = awesome_date[4] + awesome_date [5]
awesome_day = awesome_date[6] + awesome_date[7]
date_command = "date -d " + awesome_month + "/" + awesome_day + "/" + awesome_year + " +%Y%j"
print(date_command)
julian_date = subprocess.Popen(date_command)
print(julian_date)
I know that the problem is within the subprocess.Popen line, but as you can see, I have to run the actual bash command as a variable since the command will likely differ for every file that is found within /home/mydir/ and I can't figure out the correct syntax to save my life. Also, just as reminder, I also need to capture the output of the subprocess.Popen because I need the STDOUT to rename the original awesome_file with.