diff --git a/plot_heatmaps.py b/plot_heatmaps.py index 2af217f..6eb7859 100644 --- a/plot_heatmaps.py +++ b/plot_heatmaps.py @@ -87,6 +87,37 @@ def process(yaml_name): arcpy.mapping.UpdateLayer(df, update_layer, symbology_layer, 'TRUE') arcpy.RefreshTOC() + # Prepare output directories + datestr = re.search('\d+$', base_name).group() + current_date = '{}-{}-{}'.format(datestr[:4], datestr[4:6], datestr[6:]) + output_dir_current = os.path.join(output_jpg_dir, current_date) + output_dir_latest = os.path.join(output_jpg_dir, 'latest') + output_dirs = [output_dir_current] + + # Create output directories + for dir_name in [output_dir_current, output_dir_latest]: + if not os.path.isdir(dir_name): + os.makedirs(dir_name) + + # Check dates of all output folders that exist so far + all_dates = [ + d for d in os.listdir(output_jpg_dir) + if re.match('\d{4}-\d{2}-\d{2}', d) + ] + + # Export to 'latest' if current survey is most recent + is_latest = current_date == sorted(all_dates)[-1] + if is_latest: + output_dirs.append(output_dir_latest) + + # Export to jpg + for output_dir in output_dirs: + page_name = ddp.pageRow.Beach + jpg_name = os.path.join(output_dir, page_name + '.jpg') + + arcpy.mapping.ExportToJPEG( + mxd, jpg_name, resolution=200, jpeg_quality=80) + # Activate data driven pages ddp = mxd.dataDrivenPages @@ -99,7 +130,8 @@ def process(yaml_name): jpg_name = os.path.join(output_jpg_dir, page_name + '.jpg') # Export to jpg - arcpy.mapping.ExportToJPEG(mxd, jpg_name, resolution=200, jpeg_quality=80) + arcpy.mapping.ExportToJPEG( + mxd, jpg_name, resolution=200, jpeg_quality=80) def main():