def delete_from_s3(self, file_id):
        try:
            conn = database_conn.connection()
            cur = conn.cursor()
            sql = "select * from image_storage where id=" + str(
                file_id) + " and active=0"
            cur.execute(sql)
            output = cur.fetchall()
            if (len(output) == 0):
                response = {
                    "status": "Sucess",
                    "code": 400,
                    "message": "File with Id " + str(file_id) + " not found"
                }
                return response
            else:
                file_key = output[0][1]

                print(file_key)
                s3 = boto3.resource("s3")
                obj = s3.Object(config.bucket_name, file_key)
                obj.delete()
                table_response = self.delete_from_table(file_id)
                return table_response
        except:
            response = {
                "status": "Failed",
                "code": 400,
                "message": "API Failed while deleting file"
            }
            return response
Exemple #2
0
 def Check_file(self, file_name):
     conn = database_conn.connection()
     cur = conn.cursor()
     sql = "select * from image_storage where active=0 and image_name='" + str(
         file_name) + "'"
     cur.execute(sql)
     output = cur.fetchall()
     return len(output)
Exemple #3
0
 def search_table(self,search_string):
     conn = database_conn.connection()
     try:
         cur = conn.cursor()
         sql = "select * from image_storage where active=0 and image_name like '%"+str(search_string)+"%'"
         cur.execute(sql)
         output = cur.fetchall()
         return output
     except Exception as e:
         print(e)
         return 404
Exemple #4
0
    def insert_data(self, data):
        try:
            json_data = []
            for i in data:
                json_data.append(data[i])
            database_conn.connection().insert_many(json_data)
            response = {
                "status": "success",
                "code": 200,
                "message": "Data Updated Sucessfully",
            }
            return response
        except Exception as e:
            response = {
                "status": "Failed",
                "code": 400,
                "message": "API Failed while inserting to database"
            }

            return response
Exemple #5
0
 def Insert_to_DB(self, file_name, path):
     conn = database_conn.connection()
     try:
         cur = conn.cursor()
         sql = "insert into image_storage (image_name,image_path,active) values ('" + str(
             file_name) + "','" + str(path) + "','" + str(0) + "')"
         cur.execute(sql)
         conn.commit()
         return 200
     except Exception as e:
         print(e)
         return 400
Exemple #6
0
    def update_data_db(self, symbol, data):
        try:
            filter = {"symbol": symbol}
            updata_values = data
            res = database_conn.connection().update_one(filter, updata_values)
            response = {
                "status": "success",
                "code": 200,
                "message": "Data Fetched Sucessfully",
                "data": updata_values
            }
            return response
        except Exception as e:
            print(e)
            response = {
                "status": "Failed",
                "code": 400,
                "message": "API Failed while updating to database"
            }

            return response
    def delete_from_table(self, file_id):
        conn = database_conn.connection()
        try:
            cur = conn.cursor()
            sql = "UPDATE image_storage SET active=" + str(
                1) + " where id=" + str(file_id)

            cur.execute(sql)
            conn.commit()
            response = {
                "status": "success",
                "code": 200,
                "message": "Image Deleted Sucessfully",
            }
            return response
        except Exception as e:
            response = {
                "status": "Failed",
                "code": 400,
                "message": "API Failed while updated to database"
            }
            return response
Exemple #8
0
    def get_data(self, symbol):
        try:
            res = database_conn.connection().find({"symbol": symbol})
            response_data = []
            for doc in res:
                response_data.append(doc)
            response = {
                "status": "success",
                "code": 200,
                "message": "Data Fetched Sucessfully",
                "data": response_data
            }
            return response
        except Exception as e:
            print(e)
            response = {
                "status": "Failed",
                "code": 400,
                "message": "API Failed while Fetching from database"
            }

            return response