def post(self):
        payload = Website.parser.parse_args()
        # check if this website resource was already created
        site = WebsiteModel.find_by_src(src=payload['src'])
        if site:
            return {
                "message": f"The site {payload['src']} was already posted."
            }
        # create website model and save it to db
        site = WebsiteModel(**payload)
        try:
            site.save_to_db()
        except:
            return {
                'message':
                'An error occurred while creating the new site resource.'
            }, 500

        # scrapping site & adding pictures
        images = scrap_images(
            url=payload['src']
        )  # TODO: check if such picture already exists in the db by hashing it

        # save each picture info to the db
        for img in images:
            picture = PictureModel(**img, website_id=site.id)
            picture.save_to_db()

        return site.json(), 201
    def post(cls, id_tourist_spot):
        # POST /tourist-spot/<id>/picture
        data = cls.parser.parse_args()

        picture = PictureModel(**data)
        try:
            picture.save_to_db()
        except:
            return {"Messege": "An error occured inserting the picture."}, 500
        return picture.json(), 201
Beispiel #3
0
    def post(self):
        data = Picture.parser.parse_args()
        picture = PictureModel(**data)
        picture.image = data.username + data.date + ".png"
        merge_image(data.image, data.icon, picture.image)
        #print(merge_image(data.image, data.icon))

        try:
            picture.save_to_db()
        except:
            return {"message": "An error occured inserting the picture."}, 500
        return {"message": "Success"}
Beispiel #4
0
 def get(self, page):
     items = PictureModel.find_by_page(page)
     pictures = [x.json() for x in items[0]]
     for i, v in enumerate(pictures):
         pictures[i]['image'] = img_base64(v['image'])
     return {'pictures': pictures, 'count': items[1]}
     """ items = PictureModel.find_by_page(page)        
Beispiel #5
0
 def put(self, id):
     data = AddLike.parser.parse_args()
     picture = PictureModel.find_by_id(id)
     picture.like = data.like
     picture.save_to_db()
     #sendMail("testing")
     return picture.json()
Beispiel #6
0
    def put(self, id):
        data = AddComment.parser.parse_args()
        picture = PictureModel.find_by_id(id)
        if picture.comments is None:
            picture.comments = data['comments']
        else:
            picture.comments = picture.comments + data['comments']

        picture.save_to_db()
        return picture.json()
 def get(self, id_tourist_spot):
     # GET /tourist-spot/<id>/picture
     return {
         "picture_list":
         list(
             map(
                 lambda x: x.json(),
                 PictureModel.find_pictures_by_tourist_spot_id(
                     id_tourist_spot)))
     }
Beispiel #8
0
 def get(self, id):
     picture = PictureModel.find_by_id(id)
     if picture:
         return picture.json()
     return {'message': 'Picture not found'}, 404
Beispiel #9
0
 def delete(self, id):
     picture = PictureModel.find_by_id(id)
     if picture:
         picture.delete_from_db()
     return ({'mesage': 'Picture deleted'})
Beispiel #10
0
    def put(self, id):
        data = Picture.parser.parse_args()
        picture = PictureModel.find_by_id(id)

        if picture is None:
            picture = PictureModel(**data)

        else:
            picture.image = data['image']
            picture.date = data['date']
            picture.like = data['like']
            picture.comments = data['comments']
            picture.username = data['username']

        picture.save_to_db()
        return picture.json()
Beispiel #11
0
 def delete(self, id):
     picture = PictureModel.find_by_id(id)
     os.remove("images/" + picture.username + picture.date + ".png")
     if picture:
         picture.delete_from_db()
     return ({'mesage': 'Picture deleted'})
Beispiel #12
0
 def delete(self):
     PictureModel.delete_all()
     return ({'mesage': 'All Picturelist deleted'})
Beispiel #13
0
 def get(self, _id):
     item = PictureModel.find_by_id(_id)
     if item:
         return item.json()
     return {'message': 'Picture not found'}, 404
Beispiel #14
0
 def delete(self, _id):
     item = PictureModel.find_by_id(_id)
     if item:
         item.delete_from_db()
     return {'message': 'Picture successfully deleted'}