Skip to content

Commit

Permalink
update nest fetch flag to store only one photo
Browse files Browse the repository at this point in the history
this is to avoid storing all images and potentially run out of disk
  • Loading branch information
Alejandro committed Jul 14, 2018
1 parent 8a4ebc1 commit 777e895
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
help="fetches last image from Nest cameras.", action='store_true')
parser.add_argument("--repeat", required=False,
help="keeps fetching new images with the delay specified in seconds.", default=-1)
parser.add_argument("--store", required=False,
help="keeps only one photo as the latest image.", default=True)

# fetch Nest camera images and store them locally
parser.add_argument("--picamera", required=False,
Expand All @@ -47,7 +49,7 @@
# Get the arguments.
if args.nest:
print("[RUN] Fetching Nest images")
lib.nest.fetch(config, int(args.repeat))
lib.nest.fetch(config, int(args.repeat), args.store == "true")

if args.picamera:
print("[RUN] Fetching Raspberry Pi Camera images")
Expand Down
13 changes: 8 additions & 5 deletions lib/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ def resize_image(filename, destination_max_width=500, destination_max_height=500
image.save(filename, "JPEG")


def store_camera_image(token):
def store_camera_image(token, store=True):
try:
print("Downloading image from cameras...")
camera_images = fetch_snapshots_urls(token)
for camera_key in camera_images:
image_url = camera_images[camera_key]
filename = timestamp_filename()
if store:
filename = timestamp_filename()
else:
filename = "live.jpg"
directory = "images/all/" + camera_key
if not os.path.exists(directory):
os.makedirs(directory)
Expand All @@ -85,12 +88,12 @@ def store_camera_image(token):
print("Exception trying to fetch camera image. Error: " + str(e))


def fetch(config, repeat=-1):
def fetch(config, repeat=-1, store=True):
token = config.get("nest", "token")
if repeat > 0:
print("repeats every " + str(repeat) + " seconds.")
while(True):
store_camera_image(token)
store_camera_image(token, store)
time.sleep(repeat)
else:
store_camera_image(token)
store_camera_image(token, store)
6 changes: 3 additions & 3 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

python app.py --nest --repeat 30 >nest.out 2>nest.err &
python app.py --predict --repeat 90 >predict.out 2>predict.err &
python app.py --nest --repeat 30 --store false >nest.out 2>nest.err &
python app.py --predict --repeat 120 >predict.out 2>predict.err &
python app.py --slack >slack.out 2>slack.err &
python app.py --slack_changes --repeat 15 >slack_changes.out 2>slack_changes.err &
python app.py --slack_changes --repeat 10 >slack_changes.out 2>slack_changes.err &

0 comments on commit 777e895

Please sign in to comment.