Skip to content

Instantly share code, notes, and snippets.

@bcjarrett
bcjarrett / consolidate_images.py
Created March 1, 2019 16:33
Recursively consolidates .TIF and .JPG images into a single directory with file names based on folder names
import glob
import os
import pathlib
import ntpath
import shutil
if __name__ == '__main__':
def get_image_files(_dir):
tif = glob.glob(f'{_dir}/**/*.tif', recursive=True)
jpg = glob.glob(f'{_dir}/**/*.jpg', recursive=True)
@bcjarrett
bcjarrett / simple_email.py
Created August 8, 2018 18:20
Simple Email Tool
import sys
from email.mime.text import MIMEText
from smtplib import SMTP_SSL, SMTPException
import logging
def admin_email(recipients, subject, content):
smtp_server = ''
sender = ''
@bcjarrett
bcjarrett / replace_commas.py
Created August 8, 2018 16:14
The laziest way to fix special characters in folder names
import os
folder = ''
x = True
while x:
renameables = []
for root, dirs, _ in os.walk(folder):
for d in dirs:
@bcjarrett
bcjarrett / compress_and_tile.bat
Created May 8, 2018 18:44
Compress and tile a geotiff
gdal_translate.exe -co COMPRESS=JPEG -co TILED=YES -co PHOTOMETRIC=RGB mosaic.tif mosaic_compressed.tif
gdaladdo --config COMPRESS_OVERVIEW JPEG --config PHTOTMETRIC_OVERVIEW RGB --config INTERLEAVE_OVERVIEW PIXEL -r average mosaic.tif 2 4 8 16
@bcjarrett
bcjarrett / pdf_merge.py
Last active August 8, 2018 18:14
Simple Python PDF Merger
import glob
from PyPDF2 import PdfFileMerger
import os
from datetime import datetime
now = datetime.now().isoformat().replace(':', '').replace('-', '').replace('.', '')
def get_pdf_files(dir_):
files = sorted(glob.glob(f'{dir_}\\*.pdf'))