-2

I am new to programming and don´t really have a clue what to do at the moment. I am currently trying to write a code with this problem. I´m using pandas to import a file (excel, csv) into python. I am now trying to automatically save a copy of this file, for every businessday. If this is working i automatically want to delete all the files from Monday till Thursday, when the new week starts. So i only have 4 copys at the end of the Month. At the start of a new Month i only want to keep the latest copy, so i only have 12 copys of the file at the end of the year. Pls excuse my bad english i hope you get what i mean. thx

  • what did you try? Where is your code? – furas Oct 07 '22 at 09:38
  • if you run code every day (and use command to write data) then it write it every day - there is nothing to automate. It needs only to use different filenames. And to delete older file you have to write own code for this - there is no automated function for this. – furas Oct 07 '22 at 09:40

1 Answers1

0

Your problem seems similar to the one in this thread : Python script to do something at the same time every day.

Once you get the "do something at the same time every day" part right, everything else is just file management, I suggest you add the current date, with proper formatting, to your files (using the datetime module), which will make it easier to check which files your script has to delete and also make files more human-readable compared to just having a bunch of "filename_number.extension" somewhere.

However given that you're only going to be doing one file download a day at most maybe you should try to find an utility to launch the script for you every day, especially if your code is going to run on your personal computer, for UNIX platforms cron is likely the way to go, if you're on Windows I think they have a task scheduler. That would spare you from having to relaunch the script manually every time you restart your computer.

Edit : Just to make it clear, if you go for the option of the above paragraph, then your script should simply be :

  • if today is a business day then download and save file
  • check if files need to be deleted and delete those who do