diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..383e8c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 Tanner and Elijah + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/server/main.py b/server/main.py index 489fc3d..a71ec6d 100644 --- a/server/main.py +++ b/server/main.py @@ -5,14 +5,26 @@ from pathlib import Path from flask import Flask, request, abort, send_from_directory from flask_cors import CORS -import power, capture, download +import power, capture, download, settings + +import logging +log = logging.getLogger('werkzeug') +if not settings.DEBUG: + log.setLevel(logging.ERROR) build_folder = Path('../client/build') output_folder = Path('./output') app = Flask(__name__, static_folder=str(build_folder), static_url_path='') CORS(app) -status = 'Standby' +STANDBY = 0 +WARMUP = 1 +CAPTURING_PHOTO = 2 +CAPTURING_GRID = 3 +WRITING = 4 +DOWNLOADING = 5 + +status = STANDBY @app.route('/api/status', methods=['GET']) def status_get(): @@ -21,7 +33,6 @@ def status_get(): @app.route('/api/clients', methods=['POST']) def clients_post(): content = request.json - print('Recieved:', content) phone = str(content['phone']) @@ -39,6 +50,7 @@ def clients_post(): client_id = folder + print('POST client:', content, 'cid:', client_id) return {'client_id': client_id} @app.route('/api/clients/', methods=['GET']) @@ -55,6 +67,7 @@ def clients_get(cid): photo_glob = path.glob('*.jpg') res['has_photos'] = bool(list(photo_glob)) + print('GET client:', cid, 'res:', res) return res @app.route('/api/clients//session', methods=['GET']) @@ -84,12 +97,14 @@ def session_delete(cid): for p in photo_glob: p.unlink() + print('DELETE session:', cid) return '' @app.route('/api/clients//session', methods=['POST']) def session_post(cid): global status + print('POST session:', cid) folder = cid path = output_folder / cid @@ -97,14 +112,14 @@ def session_post(cid): abort(404) # go through the photo taking process - status = 'Warming up' try: # warmup + status = WARMUP power.lights_on() - time.sleep(4) + time.sleep(2) power.lights_off() - time.sleep(0.5) + time.sleep(1) except BaseException as e: print('Problem with lights: {} - {}'.format(e.__class__.__name__, str(e))) print() @@ -112,27 +127,30 @@ def session_post(cid): print() abort(500) - status = 'Capturing' - # capture + status = CAPTURING_PHOTO power.lights_on() time.sleep(0.25) capture.trigger_capture() - time.sleep(1) - power.grid_on() - time.sleep(0.25) - capture.trigger_capture() - time.sleep(1) - power.grid_off() - power.lights_off() + time.sleep(2) + + #status = CAPTURING_GRID + #power.grid_on() + #time.sleep(2) + #capture.trigger_capture() + #time.sleep(2) + #power.grid_off() - status = 'Writing to files' + status = WRITING time.sleep(3) + power.lights_off() - status = 'Downloading' + status = DOWNLOADING download.download_all_photos(path) + time.sleep(3) - status = 'Standby' + status = STANDBY + print('Finished.') return '' @app.route('/')