def test_existing_map(self): db = MongoClient().geo_example db.drop_collection('disasters') db.disasters.create_index([("loc", GEOSPHERE)]) result = db.disasters.insert_many([{"loc": { 'type': "Point", 'coordinates': [ -73, 40 ] }, "name": "blah1.44", "start_datetime": datetime.now()}]) print result.inserted_ids m = Map(db) m.get_map_id(datetime.now(), [0, 0])
def do_upload_from_app(): picture = request.forms.get('picture') lat = request.forms.get('latitude') lng = request.forms.get('longitude') raw = decodestring(picture) now = datetime.now() date_filename = now.strftime("%Y%m%d-%H%M%S") + '.jpg' print date_filename grid_db = connection['grid_files'] fs = gridfs.GridFS(grid_db) fs.put(raw, filename=date_filename) # Insert the filename and other data in the pictures db hack_db = connection['hackathon'] hack_db.pictures.insert_one( {'filename': date_filename, 'datetime': now, 'latitude': lat, 'longitude': lng, 'disaster': 0} ) m = Map(hack_db) map_id = m.get_map_id(now, [float(lng), float(lat)]) hack_db.pictures.update_one({"filename": date_filename}, {"$set": {"disaster": map_id}}) # Get the image back out image = fs.get_last_version(filename=date_filename) bottle.response.content_type = 'image/jpeg' return image