import subprocess import shutil import os import random import pandas as pd #Note that this script doesn't work inside protected Windows folders (such as "Documents") #Generate a 4 digit password that they must type in as a sort of ultimate "confirmation" requirement password="Reset{:04d}".format(random.randint(0,10000)) inStr=input('Are you sure? Type "'+password+'" to reset the state of the databases and files to the "start-of-semester-state"\nThis action cannot be undone!\n') if inStr==password: subprocess.call(['cmd','/c',"python sectionCSVHelper.py"],shell=True)#run sectionCSVHelper shutil.copy("sectionsDatabase.csv", "sectionsDatabase_Orig.csv")#copy the newly generated sections database to the _orig file for reference by the section viewer shutil.copy("startOfSemesterInputs\\blankArchivedSubRequests.csv","archivedSubRequests.csv")# copy the blank archive over to the real one (to put the column headers in place) with open("lastUpdatedToken.txt", 'w') as f:# set the lastUpdatedToken to a date in the past so that all requests are "more recent" f.write("2022-10-04 15:15:51.231447") #Read the requests log and write only the first line of it back (to clear all other lines) with open('substitutionRequestForm.csv', 'r') as fin: data = fin.read().splitlines(True) with open('substitutionRequestForm.csv', 'w') as fout: fout.writelines(data[:1]) #Set all the 'counts' to zero for all staff. stfD = pd.read_csv("staffDatabase.csv",dtype=str,index_col=False) stfD['Approved Substitutions'].values[:]=0 stfD['Accepted Substitutions'].values[:]=0 stfD['Rejected Substitutions'].values[:]=0 stfD['Cancelled Substitutions'].values[:]=0 stfD['Fulfilled Substitutions'].values[:]=0 stfD.to_csv("staffDatabase.csv",index=False,index_label=False) else: print('You typed somethinge other than '+password+'. Exiting')