Skip to content
Snippets Groups Projects
Commit 604a2e41 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

add: read outline file and expose to API

parent 4238877c
No related branches found
No related tags found
1 merge request!1Server
File deleted
import json
from flask import Flask, jsonify
import sys
sys.path.append('..') # Add root directory to the system path
from data_structs import DataPoint
app = Flask(__name__)
def process_data_point(data_point: DataPoint):
try:
# Create a temporary application context
with app.app_context():
# Convert DataPoint instance to JSON string
json_data = json.dumps(data_point.__dict__)
# Write JSON object to response object
response = jsonify(json_data)
return response, 200
except Exception as e:
print(f"Error in converting point data to JSON: {e}")
return jsonify({"error": "Internal Server Error"}), 500
if __name__ == "__main__":
app.run(debug=True)
......@@ -3,7 +3,7 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
from pymongo import MongoClient
from pymongo.server_api import ServerApi
from consts import DB_NAME, COLLECTION, MONGO_URI, MONGO_CERT_PATH, SSL_CERT_PATH, SSL_KEY_PATH, HOST, PORT
from calc_model.update_map import process_data_point
from map.extract_coordinates import extract_coordinates
from data_structs import DataPoint
import atexit
import ssl
......@@ -32,11 +32,8 @@ class IceHTTP(BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(b"Root path hit!")
elif self.path == '/update_map':
# NB temporary test data
data_point_instance = DataPoint(longitude=1.0, latitude=2.0, precipitation=10.5, thickness=3.0, max_weight=50.0, safety_level=3, accuracy=8)
# Get response from process_data_point
response, status_code = process_data_point(data_point_instance)
response, status_code = extract_coordinates()
# Send the response
self.send_response(status_code)
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment