40 lines
886 B
Python
40 lines
886 B
Python
import os
|
|
import json
|
|
from pathlib import Path
|
|
from flask import Flask, request
|
|
from flask_cors import CORS
|
|
|
|
build_folder = Path('../client/build')
|
|
output_folder = Path('./output')
|
|
app = Flask(__name__, static_folder=str(build_folder), static_url_path='')
|
|
CORS(app)
|
|
|
|
@app.route('/api/clients', methods=['POST'])
|
|
def clients():
|
|
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('/')
|
|
def index():
|
|
return app.send_static_file('index.html')
|
|
|
|
app.run()
|