Web platform for sharing free data for ML and research

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

Add pictures to API

roundabout,
created on Monday, 9 September 2024, 10:52:05 (1725879125), received on Monday, 9 September 2024, 10:52:10 (1725879130)
Author identity: vlad <vlad.muntoiu@gmail.com>

2128807f643ffa8457ec77c3de79a4e9ee3ee394

app.py

@@ -879,3 +879,38 @@ def query_pictures():

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                response.headers["Content-Type"] = "application/json"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                return response
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @app.route("/api/picture/<int:id>/")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def api_picture(id):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            resource = db.session.get(PictureResource, id)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if resource is None:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                flask.abort(404)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            json_resource = {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "id": resource.id,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "title": resource.title,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "description": resource.description,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "timestamp": resource.timestamp.timestamp(),
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "origin_url": resource.origin_url,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "author": resource.author_name,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "file_format": resource.file_format,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "width": resource.width,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "height": resource.height,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "nature": resource.nature_id,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "licences": [licence.licence_id for licence in resource.licences],
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "replaces": resource.replaces_id,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "replaced_by": resource.replaced_by_id,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "regions": [],
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                "download": config.ROOT_URL + flask.url_for("raw_picture", id=resource.id),
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            }
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            for region in resource.regions:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                json_resource["regions"].append({
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    "object": region.object_id,
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    "type": region.json["type"],
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    "shape": region.json["shape"],
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                })
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            response = flask.jsonify(json_resource)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            response.headers["Content-Type"] = "application/json"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return response