Skip to content

Instantly share code, notes, and snippets.

@hazho
Last active March 2, 2023 08:54
Show Gist options
  • Save hazho/951a7c1afce50785798077e4c332b76e to your computer and use it in GitHub Desktop.
Save hazho/951a7c1afce50785798077e4c332b76e to your computer and use it in GitHub Desktop.
questions to clarify the requirements
# at Line Number 42, replace by this code until Line: 77 that contains (# Create a URL route in our application for "/")
# Create a URL route in our application for "/fill_json"
@app.route('/fill_json', methods=['GET', 'POST'])
def fill_available_data_types():
if request.method == 'POST':
json_data = request.json
print(json_data)
cleaned_data_types = []
our_accepted_list_of_data_type = ["ECG", "Floorplan", "Doorcode", "Rescue card", "DAR", "Video", "Audio"]
available_data = json_data["available_data_types"]
if type(available_data) == list:
print("it is list")
for data_type in available_data:
if data_type in our_accepted_list_of_data_type:
cleaned_data_types.append(data_type)
else:
return {"message": f"the {data_type} is not among the acceptable data types, please reconfirm you entered the data types that are corresponding to any of ({our_accepted_list_of_data_type})."}
print(cleaned_data_types)
with open("datatypes.json", "w") as json_file: json_file.write(str(cleaned_data_types))
return {"message": "available_data_types had been posted", "available_data_types are": cleaned_data_types}
elif type(available_data) == dict:
print("it is Dict")
for data_type in available_data.keys():
if data_type in our_accepted_list_of_data_type:
cleaned_data_types.append(data_type)
else:
return {"message": f"the {data_type} is not among the acceptable data types, please reconfirm you entered the data types that are corresponding to any of ({our_accepted_list_of_data_type})."}
print(cleaned_data_types)
with open("datatypes.json", "w") as json_file: json_file.write(str(cleaned_data_types))
return {"message": "available_data_types had been posted", "available_data_types are": cleaned_data_types}
elif type(available_data) == str:
return {"message": type(available_data)}
else:
return {"message": f"the information you sent are not in a form that accepted {type(available_data)} is not of (string, list/array and/or dictionary/object) please reconfirm you entered the data correctly."}
if request.method == 'GET':
return {"message": "this is get only"}
{
"Provided_Information":
{
"ecg": true,
"floorplan": true,
"video": true,
"dar": true,
"doorcode": false,
"audio_stream": false,
"recue_sheet": true,
"crypto_data": false
}
}
@hazho
Copy link
Author

hazho commented Jan 24, 2023

in file templates/home.html

{% for datatype in avail_data %}
	<input type="checkbox" id="{{datatype}}" name="{{datatype}}">
	<label for="{{datatype}}">{{datatype}}</label>
{% endfor %}
<textarea name="data_types" id="" cols="100" > </textarea>
<script>
	let form=document.querySelector('form');
	fetch('http://localhost:5555/fill_json', {
		headers:{"Content-Type":"application/json"},
		method: 'POST', body: `${ form.data_types.value }`
		})
		.then((response) => response.text())
		.then((result) => {
		console.log('Success:', result);
		})
		.catch((error) => {
		console.error('Error:', error);
		});
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment