def setUp(self): self.europe = Continent("Europe", 2) self.scotland = Country("Scotland", self.europe, 1) self.iceland = Country("Iceland", self.europe, 3) self.glencoe = Location("Glencoe", "This is stunning location, i need to see it", False, self.scotland, 1) self.godafoss = Location( "Godafoss", "The most amazing waterfall i have ever seen", True, self.iceland, 2) self.glencoe_photo = Photo("devils_pulpit.jpg", True, self.glencoe, 1) self.godafoss_photo_01 = Photo("marina_sands01.jpg", True, self.godafoss, 2) self.godafoss_photo_02 = Photo("marina_sands01.jpg", True, self.godafoss)
def select(id): # create sql query without values sql = "SELECT * FROM photos WHERE id = %s" # create list with values required by sql query values = [id] # execute sql query result = run_sql(sql, values)[0] # convert return which is a single element list of dictionaries into a continent object photo = Photo(result["filename"], result["mine"], location_repository.select(result['location_id']),result["id"]) # return the result return photo
def select_all(): # set return variable as empty list photos = [] # create sql query without values sql = "SELECT * FROM photos" # execute sql query results = run_sql(sql) # convert return which is a single element list of dictionaries into list of countries objects for result in results: photo = Photo(result["filename"], result["mine"], location_repository.select(result['location_id']),result["id"]) photos.append(photo) # return the result return photos
async def create_dog(dog: DogSchema): local = next(get_db()) length_dog = local.query(Dog).count() length_sight = local.query(Sighting).count() length_photo = local.query(Photo).count() sighting = Sighting( sighting_id=length_sight + 1, dog_id=length_dog + 1, latitude=dog.location[0], longitude=dog.location[1], ) dog_model = Dog( dog_id=length_dog + 1, breed=dog.breed, description=dog.description, status=dog.status, ) local.add(dog_model) local.add(sighting) if dog.url: photo = Photo(photo_id=length_photo + 1, subject_id=length_dog + 1, photo_url=dog.url) local.add(photo) local.commit() local.refresh(photo) else: url = "./images/PUPFINDER.png" photo = Photo(photo_id=length_photo + 1, subject_id=length_dog + 1, photo_url=url) local.add(photo) local.commit() local.refresh(dog_model) local.refresh(sighting) return {"dog": dog_model, "sight": sighting}
def photos(aid): if 'uid' in session: if 'file' not in request.files: return abort(401) file = request.files['file'] if file.filename == '': return abort(400) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) a = services.serviceSettings.a.findByAid(aid) if a == None: abort(404) if a.user != services.serviceSettings.u.findByUid(session['uid']): abort(403) a.photos = [Photo(image=app.config['UPLOAD_FOLDER']+filename, content=request.form['content'], created_at=datetime.utcnow())] services.serviceSettings.a.addAlbum(a) return Response(status=201) else: abort(401)
def post(self): json_string = self.request.body dict_object = json.loads(json_string) url = dict_object['url'] stream_id = dict_object['stream_id'] lat = dict_object['lat'] lon = dict_object['lon'] photo_result = Photo.from_url(url) if not photo_result: photo = Photo(url=url, stream_id=stream_id, lat=lat, lon=lon) photo_key = photo.put() geopoint = search.GeoPoint(lat, lon) search_index = search.Document( doc_id= str(stream_id), fields=[search.TextField(name='url', value=url), search.GeoField(name='geopoint', value=geopoint) ]) result = search.Index(name='photo').put(search_index)
def create(record): db.session.add(record) db.session.commit() # Create admin user from models.users import Users from models.photo import Photo if not Users.query.filter_by(username='******').first(): create(Users(username='******', email='*****@*****.**')) create(Users(username='******', email='*****@*****.**')) if not Photo.query.filter_by(name='photo1').first(): with open( "/Users/tojo/Personel/easy_photo_share/static/images/portfolio/1.jpg", "rb") as image_file: create(Photo(name='photo1', base64=base64.b64encode(image_file.read()))) with open( "/Users/tojo/Personel/easy_photo_share/static/images/portfolio/2.jpg", "rb") as image_file: create(Photo(name='photo2', base64=base64.b64encode(image_file.read()))) with open( "/Users/tojo/Personel/easy_photo_share/static/images/portfolio/3.jpg", "rb") as image_file: create(Photo(name='photo3', base64=base64.b64encode(image_file.read()))) if __name__ == "__main__": app.run()
from models.photo import Photo list_photos = [ Photo( url= "https://images.squarespace-cdn.com/content/v1/5e9d994b2f1c2d4970c8acdb/1587389963053-73XU5GRBB3G5MV5LXRMY/ke17ZwdGBToddI8pDm48kIkgHTxUnlW7VysxtwKs7v57gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z4YTzHvnKhyp6Da-NYroOW3ZGjoBKy3azqku80C789l0ivq7Q1ckvJa8MA8qNUlEObOCsMVUGH9o4TViecrUGpmccNK2aHmPI1EqrJ3R2V6NQ/DSC_5828.jpg?format=1500w", caption="Junior World Champion Hannah Slaney eyes up the next hold", user_id=4), Photo( url= "https://images.squarespace-cdn.com/content/v1/5e9d994b2f1c2d4970c8acdb/1587387546125-9XVQR4EEFCOILIYCY3AZ/ke17ZwdGBToddI8pDm48kNiEM88mrzHRsd1mQ3bxVct7gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z4YTzHvnKhyp6Da-NYroOW3ZGjoBKy3azqku80C789l0s0XaMNjCqAzRibjnE_wBlkZ2axuMlPfqFLWy-3Tjp4nKScCHg1XF4aLsQJlo6oYbA/IMG_6815.jpg?format=1000w", caption= "Two sisters share a special moment before the wedding ceremony", user_id=4), Photo( url= "https://images.squarespace-cdn.com/content/v1/5e9d994b2f1c2d4970c8acdb/1587388874581-3ICCJC5DUB00ZEVLFMWK/ke17ZwdGBToddI8pDm48kKErbpWhp7vl1zMeCVdM4Ld7gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z4YTzHvnKhyp6Da-NYroOW3ZGjoBKy3azqku80C789l0lCYWGxfdB_uf1_ERfebHZ7UL1AJZpeUglh-dzBN3nU2Mw6gPXzsdsst52ojjUXzvA/DSC_0867.jpg?format=1000w", caption= "The hills of Italy, as viewed from just over the Slovakian border", user_id=4), Photo( url= "https://images.squarespace-cdn.com/content/v1/5e9d994b2f1c2d4970c8acdb/1587391639128-1B50U4O03IXYBP2TA8Z5/ke17ZwdGBToddI8pDm48kLR2rgEg1jPu1GtjV4K1vZ97gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z4YTzHvnKhyp6Da-NYroOW3ZGjoBKy3azqku80C789l0scl71iiVnMuLeEyTFSXT3qwhEKW1IfUKL5GUNLdDa9MjuPXcXiDenG_NSvE-2lGCg/DSC_9731+%281%29-2.jpg?format=750w", caption= "Climbers on the Vallée Blanche with the Grand Jorasses in the background", user_id=4), Photo( url= "https://images.squarespace-cdn.com/content/v1/5e9d994b2f1c2d4970c8acdb/1587556035572-Z57N685K43LUNM7M2MUQ/ke17ZwdGBToddI8pDm48kKg9gHUxzC8TFjTv4MbkSwl7gQa3H78H3Y0txjaiv_0fDoOvxcdMmMKkDsyUqMSsMWxHk725yiiHCCLfrh8O1z4YTzHvnKhyp6Da-NYroOW3ZGjoBKy3azqku80C789l0prfa1Z6IeUrCPboCAmmHZkq_ORj1s9iZK8iaWQvAxQZ3OpNqQjmR1zGWZGBfK589Q/DSC_0796.jpg?format=1500w", caption= "Time for a tea break by the lake on a motorcycle trip through Switzerland",
location_repository.save(marina_bay_gardens) location_repository.save(devils_pulpit) # populates locations table with to be visited places bluelagoon = Location("Blue Lagoon", "Amazing thermal pools", False, iceland) sentosa = Location("Sentosa", "Some entertainment there", False, singapore) alps = Location("Alps", "Excellent glacier photo oportunity", False, austria) namibia_dunes = Location("Namibia Dunes", "Excellent dunes photo oportunity", False, namibia) location_repository.save(bluelagoon) location_repository.save(sentosa) location_repository.save(alps) location_repository.save(namibia_dunes) photo_repository.save(Photo("Clark01.jpg", True, clark_quay)) photo_repository.save(Photo("Godafoss02.jpg", True, godafoss)) photo_repository.save(Photo("MarinaGardens01.jpg", True, marina_bay_gardens)) photo_repository.save(Photo("Glencoe01.jpg", True, glencoe)) photo_repository.save(Photo("Lava field.jpg", True, lava_field)) photo_repository.save(Photo("MarinaGardens02.jpg", True, marina_bay_gardens)) photo_repository.save(Photo("Glencoe02.jpg", True, glencoe)) photo_repository.save(Photo("Marina01.jpg", True, marina_sands_bay)) photo_repository.save(Photo("devils_pulpit.jpg", True, devils_pulpit)) photo_repository.save(Photo("Glencoe03.jpg", True, glencoe)) photo_repository.save(Photo("Marina02.jpg", True, marina_sands_bay)) photo_repository.save(Photo("marina_sands01.jpg", True, marina_sands_bay)) photo_repository.save(Photo("Glenfinnan01.jpg", True, glenfinnan)) photo_repository.save(Photo("Marina03.jpg", True, marina_sands_bay)) photo_repository.save(Photo("Godafoss01.jpg", True, godafoss)) photo_repository.save(Photo("Marina04.jpg", True, marina_sands_bay))