mirror of
				https://github.com/StefBuwalda/ProjectIOT.git
				synced 2025-10-30 19:29:57 +00:00 
			
		
		
		
	 2f7a499c91
			
		
	
	2f7a499c91
	
	
	
		
			
			Added logs.html for the logs page Changed dashboard.html so the numberplates show on the dashboard Moved models.py to to the dashboard folder
		
			
				
	
	
		
			31 lines
		
	
	
		
			913 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			913 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| from flask import Blueprint, request, jsonify
 | |
| from application import db
 | |
| from application.dashboard.models import AllowedPlate, LoggedItem
 | |
| from application.api.image_processing import process_image
 | |
| from datetime import datetime
 | |
| import asyncio
 | |
| 
 | |
| api_blueprint = Blueprint("api", __name__, template_folder="templates")
 | |
| 
 | |
| 
 | |
| # API to process vehicle
 | |
| @api_blueprint.route("/", methods=["POST"])
 | |
| def data():
 | |
|     data = request.data
 | |
|     np = asyncio.run(process_image(image=data))
 | |
| 
 | |
|     # Check if the found plate is allowed to exit
 | |
|     allowed = AllowedPlate.query.filter_by(plate=np).first() is not None
 | |
|     db.session.add(  # Log the found numberplate and status
 | |
|         LoggedItem(plate=np, allowed=allowed, datetime=datetime.now())
 | |
|     )
 | |
|     db.session.commit()
 | |
| 
 | |
|     # Return decision to Pico
 | |
|     return jsonify(
 | |
|         {
 | |
|             "message": "Image sent succesfully",
 | |
|             "status": allowed,
 | |
|         }
 | |
|     )
 |