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 os
import sys import sys
import glob
import time import time
import pytz import pytz
from io import BytesIO from io import BytesIO
@ -29,6 +30,17 @@ SILENT = True
username = '' username = ''
password = '' 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(): def start_session():
"""Start automated browser session. """Start automated browser session.
@ -146,9 +158,8 @@ def get_next_image(driver, cookies):
t_local = t_utc.astimezone(pytz.timezone(TIMEZONE)) t_local = t_utc.astimezone(pytz.timezone(TIMEZONE))
# Save image # Save image
ts = t_local.strftime jpg_name = os.path.join(current_hightide_dir, 'images',
jpg_name = os.path.join(OUTPUT_DIR, ts('%Y'), ts('%Y-%m-%d'), ts('%H'), t_local.strftime('%Y-%m-%d_%H-%M-%S%z') + '.jpg')
ts('%Y-%m-%d_%H-%M-%S%z') + '.jpg')
os.makedirs(os.path.dirname(jpg_name), exist_ok=True) os.makedirs(os.path.dirname(jpg_name), exist_ok=True)
im.save(jpg_name) im.save(jpg_name)

Loading…
Cancel
Save