Save images in separate folder for each high tide

hightide
Dan Howe 5 years ago
parent 509c8100bf
commit a65de58d14

@ -5,6 +5,7 @@ Open an automated selenium webdriver, and download images from Live View mode.
import os
import sys
import glob
import time
import pytz
from io import BytesIO
@ -29,6 +30,17 @@ SILENT = True
username = ''
password = ''
# Get water level of next high tide
pwd = os.path.dirname(os.path.abspath(__file__))
next_high_tide = glob.glob(pwd + '/NEXT_HIGH_TIDE=*')[0]
height = next_high_tide.rsplit('_', 1)[-1]
# Get current time
now = datetime.now()
year = now.strftime('%Y')
timestamp = now.strftime('%Y-%m-%d_%H-%M')
current_hightide_dir = os.path.join(OUTPUT_DIR, year, f'{timestamp}_{height}')
def start_session():
"""Start automated browser session.
@ -146,9 +158,8 @@ def get_next_image(driver, cookies):
t_local = t_utc.astimezone(pytz.timezone(TIMEZONE))
# Save image
ts = t_local.strftime
jpg_name = os.path.join(OUTPUT_DIR, ts('%Y'), ts('%Y-%m-%d'), ts('%H'),
ts('%Y-%m-%d_%H-%M-%S%z') + '.jpg')
jpg_name = os.path.join(current_hightide_dir, 'images',
t_local.strftime('%Y-%m-%d_%H-%M-%S%z') + '.jpg')
os.makedirs(os.path.dirname(jpg_name), exist_ok=True)
im.save(jpg_name)

Loading…
Cancel
Save