Skip to content

Timestamping Fullscreen Snapshots

Jeffrey Walter edited this page Feb 12, 2020 · 3 revisions

master

from arlo import Arlo
import time
import wand.image
import wand.font

# Written by: [apsteinmetz](https://github.com/apsteinmetz) -- Thank you!
# See: https://github.com/jeffreydwalter/arlo/issues/101
def time_stamp(filename, text_size=40, position="north_west"):
    # requirements:
    # wand python library. See http://docs.wand-py.org/
    # imagemagick. See https://imagemagick.org/index.php
    #
    # valid position (aka 'gravity') argument types: 'forget', 'north_west', 'north', 'north_east',
    # 'west', 'center', 'east', 'south_west', 'south', 'south_east', 'static'

    font = wand.font.Font(path='', size=text_size, stroke_color="snow2")  # use default font
    timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())

    with wand.image.Image(filename=filename) as img:
        img.caption(timestamp, font=font, gravity=position)
        img.save(filename=filename)


USERNAME = 'user@example.com'
PASSWORD = 'supersecretpassword'

try:
	# Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached.
	# Subsequent successful calls to login will update the oAuth token.
	arlo = Arlo(USERNAME, PASSWORD)
	# At this point you're logged into Arlo.

	# Get the list of devices and filter on device type to only get the basestation.
	# This will return an array which includes all of the basestation's associated metadata.
	basestations = arlo.GetDevices('basestation')

        # Get the list of devices and filter on device type to only get the camera.
        # This will return an array which includes all of the camera's associated metadata.
        cameras = arlo.GetDevices('camera')

        # Tells the Arlo basestation to trigger a snapshot on the given camera.
        # This snapshot is not instantaneous, so this method waits for the response and returns the url
        # for the snapshot, which is stored on the Amazon AWS servers. 
        snapshot_url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0])
        
        # This method requests the snapshot for the given url and writes the image data to the location specified.
        # In this case, to the current directory as a file named "snapshot.jpg"
        # Note: Snapshots are in .jpg format.
        arlo.DownloadSnapshot(snapshot_url, 'snapshot.jpg')

        # Timestamp the snapshot.
        time_stamp('snapshot.jpg')

except Exception as e:
    print(e)