Compare commits
No commits in common. "b1aaffa4dbc2b67afc8fb7003d92380057e78bc0" and "b0aec2cfd13065d46907cc678582fd4b91984760" have entirely different histories.
b1aaffa4db
...
b0aec2cfd1
1
server/.gitignore
vendored
1
server/.gitignore
vendored
|
@ -103,4 +103,3 @@ ENV/
|
||||||
*.swo
|
*.swo
|
||||||
|
|
||||||
paramiko.log
|
paramiko.log
|
||||||
output/
|
|
||||||
|
|
|
@ -18,10 +18,10 @@ def download(ip, dest):
|
||||||
|
|
||||||
for f in files:
|
for f in files:
|
||||||
source_file = '/3dscan/' + f
|
source_file = '/3dscan/' + f
|
||||||
dest_file = dest / f
|
dest_file = dest + f
|
||||||
print('Grabbing file', source_file)
|
print('Grabbing file', source_file)
|
||||||
sftp.get(source_file, dest_file)
|
sftp.get(source_file, dest_file)
|
||||||
#sftp.remove(source_file)
|
sftp.remove(source_file)
|
||||||
|
|
||||||
if sftp: sftp.close()
|
if sftp: sftp.close()
|
||||||
if transport: transport.close()
|
if transport: transport.close()
|
||||||
|
@ -29,7 +29,10 @@ def download(ip, dest):
|
||||||
print('Finished downloading from', ip)
|
print('Finished downloading from', ip)
|
||||||
|
|
||||||
def download_all_photos(dest):
|
def download_all_photos(dest):
|
||||||
if not dest.exists():
|
if not dest.endswith('/'):
|
||||||
|
raise Exception('Destination must end with /')
|
||||||
|
|
||||||
|
if not os.path.exists(dest):
|
||||||
raise Exception('Destination does not exist')
|
raise Exception('Destination does not exist')
|
||||||
|
|
||||||
print('Downloading all photos to', dest)
|
print('Downloading all photos to', dest)
|
||||||
|
@ -37,7 +40,3 @@ def download_all_photos(dest):
|
||||||
for ip in settings.RASPBERRY_IPS:
|
for ip in settings.RASPBERRY_IPS:
|
||||||
t = threading.Thread(target=download, args=(ip, dest))
|
t = threading.Thread(target=download, args=(ip, dest))
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
from pathlib import Path
|
|
||||||
download_all_photos(Path('test/'))
|
|
||||||
|
|
119
server/main.py
119
server/main.py
|
@ -1,123 +1,12 @@
|
||||||
import os
|
from flask import Flask
|
||||||
import json
|
|
||||||
import time
|
|
||||||
from pathlib import Path
|
|
||||||
from flask import Flask, request, abort, send_from_directory
|
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
import power, capture, download
|
build_folder = '../client/build'
|
||||||
|
app = Flask(__name__, static_folder=build_folder, static_url_path='')
|
||||||
build_folder = Path('../client/build')
|
|
||||||
output_folder = Path('./output')
|
|
||||||
app = Flask(__name__, static_folder=str(build_folder), static_url_path='')
|
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
|
||||||
@app.route('/api/clients', methods=['POST'])
|
|
||||||
def clients_post():
|
|
||||||
content = request.json
|
|
||||||
print('Recieved:', content)
|
|
||||||
|
|
||||||
phone = str(content['phone'])
|
|
||||||
|
|
||||||
for i in range(1, 100):
|
|
||||||
suffix = str(i).zfill(3)
|
|
||||||
folder = phone + '_' + suffix
|
|
||||||
path = output_folder / folder
|
|
||||||
if not path.exists():
|
|
||||||
break
|
|
||||||
|
|
||||||
path.mkdir()
|
|
||||||
info_file = path / 'info.json'
|
|
||||||
info_file.touch()
|
|
||||||
info_file.write_text(json.dumps(content, indent=4))
|
|
||||||
|
|
||||||
client_id = folder
|
|
||||||
|
|
||||||
return {'client_id': client_id}
|
|
||||||
|
|
||||||
@app.route('/api/clients/<cid>', methods=['GET'])
|
|
||||||
def clients_get(cid):
|
|
||||||
folder = cid
|
|
||||||
path = output_folder / cid
|
|
||||||
|
|
||||||
if not path.exists():
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
info_file = path / 'info.json'
|
|
||||||
info_text = info_file.read_text()
|
|
||||||
res = json.loads(info_text)
|
|
||||||
photo_glob = path.glob('*.jpg')
|
|
||||||
res['has_photos'] = bool(list(photo_glob))
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
@app.route('/api/clients/<cid>/session', methods=['GET'])
|
|
||||||
def session_get(cid):
|
|
||||||
folder = cid
|
|
||||||
path = output_folder / cid
|
|
||||||
|
|
||||||
if not path.exists():
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
photo_glob = path.glob('*.jpg')
|
|
||||||
res = {}
|
|
||||||
res['photos'] = [x.name for x in photo_glob]
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
@app.route('/api/clients/<cid>/session', methods=['DELETE'])
|
|
||||||
def session_delete(cid):
|
|
||||||
folder = cid
|
|
||||||
path = output_folder / cid
|
|
||||||
|
|
||||||
if not path.exists():
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
photo_glob = path.glob('*.jpg')
|
|
||||||
|
|
||||||
for p in photo_glob:
|
|
||||||
p.unlink()
|
|
||||||
|
|
||||||
return ''
|
|
||||||
|
|
||||||
@app.route('/api/clients/<cid>/session', methods=['POST'])
|
|
||||||
def session_post(cid):
|
|
||||||
folder = cid
|
|
||||||
path = output_folder / cid
|
|
||||||
|
|
||||||
if not path.exists():
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
# go through the photo taking process
|
|
||||||
|
|
||||||
# warmup
|
|
||||||
power.lights_on()
|
|
||||||
time.sleep(4)
|
|
||||||
power.lights_off()
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
# capture
|
|
||||||
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()
|
|
||||||
|
|
||||||
download.download_all_photos(path)
|
|
||||||
|
|
||||||
return ''
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return app.send_static_file('index.html')
|
return app.send_static_file('index.html')
|
||||||
|
|
||||||
@app.route('/output/<path:filename>')
|
app.run()
|
||||||
def output(filename):
|
|
||||||
return send_from_directory('output/', filename)
|
|
||||||
|
|
||||||
app.run(host='0.0.0.0')
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user