From ec8128d96a4ab813f66ab1dd3f0746db9711edc9 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 10 Mar 2021 17:37:01 -0700 Subject: [PATCH 1/3] Add debug mode to simulate a capture --- server/download.py | 10 ++++++++++ server/power.py | 2 ++ server/settings.py | 3 +++ 3 files changed, 15 insertions(+) diff --git a/server/download.py b/server/download.py index aadac12..fb56fb5 100644 --- a/server/download.py +++ b/server/download.py @@ -5,7 +5,17 @@ import paramiko import time paramiko.util.log_to_file('paramiko.log') +def fake_download(dest): + import requests, random + rnd = str(random.randint(1, 10000)) + r = requests.get('https://picsum.photos/400/300?random=' + rnd) + with open(dest / (rnd + '.jpg'), 'wb') as f: + f.write(r.content) + def download(ip, dest): + if settings.DEBUG: + fake_download(dest) + print('Downloading from', ip) port = 22 diff --git a/server/power.py b/server/power.py index 5710e23..c3f265e 100644 --- a/server/power.py +++ b/server/power.py @@ -3,6 +3,8 @@ import settings import time def np_02B_api(ip, username, password, is_on): + if settings.DEBUG: return + if is_on: endpoint = '/cmd.cgi?grp=0' else: diff --git a/server/settings.py b/server/settings.py index 648a02c..3372a69 100644 --- a/server/settings.py +++ b/server/settings.py @@ -1,3 +1,6 @@ +import os +DEBUG = os.environ['FLASK_ENV'] == 'development' + LIGHT_IP = '192.168.99.25' LIGHT_USER = 'admin' LIGHT_PASS = 'admin' From ecb8c1f8156049ba38c0a73300ef63a7cdf30c3c Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 10 Mar 2021 17:47:04 -0700 Subject: [PATCH 2/3] Detect when the system isn't connected --- server/main.py | 17 ++++++++++++----- server/settings.py | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/server/main.py b/server/main.py index 68913bf..38aa551 100644 --- a/server/main.py +++ b/server/main.py @@ -99,11 +99,18 @@ def session_post(cid): # go through the photo taking process status = 'Warming up' - # warmup - power.lights_on() - time.sleep(4) - power.lights_off() - time.sleep(0.5) + try: + # warmup + power.lights_on() + time.sleep(4) + power.lights_off() + time.sleep(0.5) + except BaseException as e: + print('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e))) + print() + print('Are you sure the system is connected?') + print() + abort(500) status = 'Capturing' diff --git a/server/settings.py b/server/settings.py index 3372a69..fa558fc 100644 --- a/server/settings.py +++ b/server/settings.py @@ -1,5 +1,5 @@ import os -DEBUG = os.environ['FLASK_ENV'] == 'development' +DEBUG = os.environ.get('FLASK_ENV', None) == 'development' LIGHT_IP = '192.168.99.25' LIGHT_USER = 'admin' From d1486b61df47b1534dd3f87d9db8f6949e993104 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 10 Mar 2021 17:49:49 -0700 Subject: [PATCH 3/3] Remove a zero --- server/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.py b/server/main.py index 38aa551..489fc3d 100644 --- a/server/main.py +++ b/server/main.py @@ -26,7 +26,7 @@ def clients_post(): phone = str(content['phone']) for i in range(1, 100): - suffix = str(i).zfill(3) + suffix = str(i).zfill(2) folder = phone + '_' + suffix path = output_folder / folder if not path.exists():