Jun-07-2023, 06:43 PM
So i have the following code that works great, updates my excel file and saves the file as expected.. BUT because we are merely updating the one excel file with the latest image, we are now wanting to archive the images when this script runs.
how can i modify this code to save off the image into the same folder with the date as the name so we can go back and look at past charts?
how can i modify this code to save off the image into the same folder with the date as the name so we can go back and look at past charts?
# CHECK IF MESSAGE IS TODAY SO THAT THE MOST CURRENT SCREENSHOT IS UPDATED IN THE FILE. if edDate == tdDate: attachments = message.Attachments # THIS ENSURES THAT THE EMAIL HAS AT LEAST 2 ATTACHMENTS BEFORE IT TRIES TO DOWNLOAD FILES THAT DONT EXIST if attachments.count >= 1: #LOOP THRU ALL ATTACHMENTS AND ONLY DOWNLOAD CSV FILES for att in attachments: p = Path(str(att).lower()) newName = "{0}_{1}".format(p.stem,p.suffix) # CHECK IF ITS A PNG FILE BEFORE ATTEMPTING TO DOWNLOAD if p.suffix == ".png": imgFileLoc = "C:\PricingVolume"+ '\\' + newName # DOWNLOAD CSV FILE ONLY WITH THE NEW FILE NAME figSaved = att.SaveASFile(imgFileLoc) #print(att) # THIS IS THE MASTER EXCEL FILE THAT IS UPDATED AT THE END WITH THE FILTERED DATA wrkb = openpyxl.Workbook() ws = wrkb.worksheets[0] img = openpyxl.drawing.image.Image(imgFileLoc) img.height = 757 img.width= 1533 img.anchor = 'A1' ws.add_image(img) wrkb.save(PeakPricingVolumeFile)