Exemplo n.º 1
0
def delete(audioFileType,id):
    """[Function which delete item form the table]

    Returns:
        [Json]: [Item id and type]
    """
    try:
        mydb = sql_connection()
        #Calling function to connecting the datbase
        mydb = sql_connection()

        #creating cursor to upload data into the database
        myCursor = mydb.cursor()

        #executing, commiting and closing all the objects 
        myCursor.execute("DELETE FROM {} where ID = {}".format(audioFileType,id))
        myCursor.close()
        mydb.close()
        
        x = {
            "requestType":"Delete",     
            "response":"200 ok",
            "audioFileType": audioFileType,
            "ID": id
        }
        
        return x

    except Exception as e:
        return str(e)
Exemplo n.º 2
0
def search():
    """[Adding new batch_time]

    Returns:
        [str]: [normal string]
    """
    #Caling function to connecting database
    mydb = sql_connection()
    try:
        if request.method == "POST":

            StudentBatchData = request.get_json()
            StudentID = StudentBatchData["STUDENTID"]

            print(StudentBatchData)

            mycursor = mydb.cursor()
            mycursor.execute(
                "SELECT* FROM student_data_ineuron WHERE STUDENT_ID = {}".
                format(StudentID))
            print("select* from student_data_ineuron where STUDENT_ID = {}".
                  format(StudentID))
            studentFullData = {"studentFullData": mycursor.fetchall()[0]}
            mycursor.close()
            mydb.close()

    except Exception as e:
        return str(e)
    return studentFullData
Exemplo n.º 3
0
def add_batch_time():
    """[Adding new batch_time]

    Returns:
        [str]: [normal string]
    """
    #Caling function to connecting database
    mydb = sql_connection()
    try:
        if request.method == "POST":

            StudentBatchData = request.get_json()
            Time = StudentBatchData["TIME"]
            MONDAY = StudentBatchData["MONDAY"]
            TUESDAY = StudentBatchData["TUESDAY"]
            WEDNESDAY = StudentBatchData["WEDNESDAY"]
            THURSDAY = StudentBatchData["THURSDAY"]
            FRIDAY = StudentBatchData["FRIDAY"]

            print(StudentBatchData)

            mycursor = mydb.cursor()
            add_student_query = "INSERT INTO student_batch_time (BTIME, MONDAY,TUESDAY,WEDNESDAY,THRUSDAY,FRIDAY) VALUES (%s,%s,%s,%s,%s,%s)"
            add_student_data = (Time, MONDAY, TUESDAY, WEDNESDAY, THURSDAY,
                                FRIDAY)
            mycursor.execute(add_student_query, add_student_data)
            mydb.commit()
            mycursor.close()
            mydb.close()

    except Exception as e:
        return e
    return StudentBatchData
Exemplo n.º 4
0
def topper():
    """[showing  batch_time]

    Returns:
        [str]: [normal string]
    """
    #Caling function to connecting database
    mydb = sql_connection()
    try:
        if request.method == "GET":

            toperNameList = []

            mycursor = mydb.cursor()
            mycursor.execute(
                "select STUDENT_NAME from student_data_ineuron where STUDENT_ID = (select STUDENT_ID from student_id_marks where ME = (select max(ME) from student_id_marks))"
            )
            toperNameList.append(mycursor.fetchall()[0][0])
            mycursor.close()

            mycursor = mydb.cursor()
            mycursor.execute(
                "select STUDENT_NAME from student_data_ineuron where STUDENT_ID = (select STUDENT_ID from student_id_marks where CSE = (select max(CSE) from student_id_marks))"
            )
            toperNameList.append(mycursor.fetchall()[0][0])
            mycursor.close()

            mycursor = mydb.cursor()
            mycursor.execute(
                "select STUDENT_NAME from student_data_ineuron where STUDENT_ID = (select STUDENT_ID from student_id_marks where civil = (select max(civil) from student_id_marks))"
            )
            toperNameList.append(mycursor.fetchall()[0][0])
            mycursor.close()

            studentTopperData = {"Topper": toperNameList}

            print(studentTopperData)

            mycursor.close()
            mydb.close()

    except Exception as e:
        return str(e)
    return studentTopperData
Exemplo n.º 5
0
def viewOne(audioFileType,id):
    """[Function having ability to show tha data compounding to request]

    Returns:
        [type]: [description]
    """
    try:
        if audioFileType == "songs":
            name = "songname"
        elif audioFileType == "podcastname":
            name = "podcast"
        elif audioFileType == "audiobook":
            name = "title"

        #Calling function to connecting the datbase
        mydb = sql_connection()

        #creating cursor to upload data into the database
        myCursor = mydb.cursor()

        #executing, commiting and closing all the objects 
        myCursor.execute("SELECT {} FROM {} WHERE ID = {}".format(name,audioFileType,id))

        #Storing all the data into list
        names = ""
        for i in myCursor:
            names = i[0]

        myCursor.close()
        mydb.close()
        
        x = {
            "requestType":"View",     
            "response":"200 ok",
            "audioFileType": audioFileType,
            "Audio": names,
            "Audio ID": id
        }
        
        return x

    except Exception as e:
        return str(e)
Exemplo n.º 6
0
def add_student():
    """[Adding new student on the the class]

    Returns:
        [str]: [added stundent name]
    """
    #Caling function to connecting database
    mydb = sql_connection()
    try:
        if request.method == "POST":

            StudentData = request.get_json()
            StudentName = StudentData["NAME"]
            StudentId = StudentData["ID"]
            Batch = StudentData["BATCH"]
            Branch = StudentData['BRANCH']

            print(StudentData)

            mycursor = mydb.cursor()
            add_student_query = "INSERT INTO student_data_ineuron (STUDENT_ID, STUDENT_NAME, BRANCH,BATCH) VALUES (%s, %s, %s, %s)"
            add_student_data = (StudentId, StudentName, Branch, Batch)
            mycursor.execute(add_student_query, add_student_data)
            mydb.commit()
            mycursor.close()

            #Adding Student_Id For marks updating
            mycursor = mydb.cursor()
            add_student_id_for_marks_query = "INSERT INTO student_id_marks (STUDENT_ID) VALUES (%s)"
            add_student_id_for_marks_data = (StudentId, )
            mycursor.execute(add_student_id_for_marks_query,
                             add_student_id_for_marks_data)

            mydb.commit()
            mycursor.close()
            mydb.close()

    except Exception as e:
        return e
    return StudentData
Exemplo n.º 7
0
def batchTime():
    """[showing  batch_time]

    Returns:
        [str]: [normal string]
    """
    #Caling function to connecting database
    mydb = sql_connection()
    try:
        if request.method == "GET":

            mycursor = mydb.cursor()
            mycursor.execute("SELECT* FROM student_batch_time")
            #print("select* from student_data_ineuron where STUDENT_ID = {}".format(StudentID))
            studentBatchTimeData = {
                "studentBatchTimeData": mycursor.fetchall()
            }
            mycursor.close()
            mydb.close()

    except Exception as e:
        return str(e)
    return studentBatchTimeData
Exemplo n.º 8
0
def student_name():
    print("------------------------------------")
    """[finding all the student having perticular batch]

    Returns:
        [list]: [list of all the student name]
        """
    #Caling function to connecting database
    mydb = sql_connection()
    try:
        if request.method == "POST":

            StudentData = request.get_json()
            StudentBATCH = StudentData["BATCH"]

            print(StudentData)

            mycursor = mydb.cursor()
            add_student_query = "SELECT STUDENT_NAME FROM student_data_ineuron WHERE BATCH = %s"
            add_student_data = (StudentBATCH, )
            mycursor.execute(add_student_query, add_student_data)

            RetriveStudentName = {}
            NameList = []
            for i in mycursor:
                NameList.append(i[0])

            RetriveStudentName["NAME"] = NameList
            print(RetriveStudentName)

            mycursor.close()
            mydb.close()
            #SuccessReturn = (StudentName +" Is added into the system having ID = "+StudentId+" ,Brach = "+Branch+" and batch = "+Batch)
    except Exception as e:
        return e
    return RetriveStudentName
Exemplo n.º 9
0
def update(audioFileType,audioID,audioMeta):
    """[summary]

    Returns:
        [type]: [description]
    """
    try:
        #Calling function to connecting the datbase
        mydb = sql_connection()

        #creating cursor to upload data into the database
        myCursor = mydb.cursor()

        #condition for various type of audio file
        if audioFileType == "songs":
            #converting upcoming string into json(dict)
            audioMeta = json.loads(audioMeta)
            id       = audioMeta["id"]
            songName = audioMeta["songname"]
            duration = audioMeta["duration"]
            dateTime = datetime.datetime.utcnow()
            formatted_date = dateTime.strftime('%Y-%m-%d %H:%M:%S')

            #Query by which data inserted into data base
            query = "UPDATE {} SET songname = %s, duration = %s, uploadtime = %s WHERE ID = %s".format(audioFileType)

            #variable that holds data, which going to the database table
            data = (songName,duration,formatted_date,id)

        elif audioFileType == "podcast":
            #converting upcoming string into json(dict)
            audioMeta         = json.loads(audioMeta)
            id                = audioMeta["id"]
            podcastName       = audioMeta["podcastname"]
            duration          = audioMeta["duration"]
            hostName          = audioMeta["hostname"]
            participents      = audioMeta["participents"]
            dateTime          = datetime.datetime.utcnow()
            formatted_date    = dateTime.strftime('%Y-%m-%d %H:%M:%S')

            #Query by which data inserted into data base
            query = "UPDATE {} SET podcastname = %s , duration = %s, uploadtime = %s, hostname = %s, participents = %s WHERE ID = %s".format(audioFileType);

            #variable that holds data, which going to the database table
            data = (podcastName,duration,formatted_date,hostName,participents,id)
            
        elif audioFileType == "audiobook":
            #converting upcoming string into json(dict)
            audioMeta      = json.loads(audioMeta)
            id             = audioMeta["id"]
            title          = audioMeta["title"]
            author         = audioMeta["author"]
            narrator       = audioMeta["narrator"]
            duration       = audioMeta["duration"]
            dateTime       = datetime.datetime.utcnow()
            formatted_date = dateTime.strftime('%Y-%m-%d %H:%M:%S')

            print(audioFileType,audioID)
            #Query by which data inserted into data base
            query = "UPDATE {} SET title = %s, author = %s, narrator = %s, duration = %s, uploadtime = %s WHERE ID = %s".format(audioFileType)

            #variable that holds data, which going to the database table
            data = (title,author,narrator,duration,formatted_date,id)

        #executing, commiting and closing all the objects
        myCursor.execute(query,data)
        mydb.commit()
        myCursor.close()
        mydb.close()

        #returning data and 200 Ok after successfully inserted data
        return "200 ok"

    except Exception as e:
        return str(e)
Exemplo n.º 10
0
def upload(audioFileType,audioMeta):
    """[uploading audio type into database]

    Args:
        audioFileType ([type]): [string]
        audioMeta ([type]): [string]
    """
    try:
        
        #variable that hold all the data comming from query string    
        """x = {
            "response":"200 Ok",
            "id":id,
            "songName":songName,
            "duration":duration,
            "dateTime":formatted_date
        }"""

        #Calling function to connecting the datbase
        mydb = sql_connection()

        #creating cursor to upload data into the database
        myCursor = mydb.cursor()

        #condition for various type of audio file
        if audioFileType == "songs":
            #converting upcoming string into json(dict)
            audioMeta = json.loads(audioMeta)
            id       = audioMeta["id"]
            songName = audioMeta["songname"]
            duration = audioMeta["duration"]
            dateTime = datetime.datetime.utcnow()
            formatted_date = dateTime.strftime('%Y-%m-%d %H:%M:%S')

            #Query by which data inserted into data base
            query = "INSERT INTO {} (ID, songname, duration, uploadtime) values (%s,%s,%s,%s)".format(audioFileType)

            #variable that holds data, which going to the database table
            data = (id,songName,duration,formatted_date)

        elif audioFileType == "podcast":
            #converting upcoming string into json(dict)
            audioMeta         = json.loads(audioMeta)
            id                = audioMeta["id"]
            podcastName       = audioMeta["podcastname"]
            duration          = audioMeta["duration"]
            hostName          = audioMeta["hostname"]
            participents      = audioMeta["participents"]
            dateTime          = datetime.datetime.utcnow()
            formatted_date    = dateTime.strftime('%Y-%m-%d %H:%M:%S')

            #Query by which data inserted into data base
            query = "INSERT INTO {} (ID, podcastname, duration, uploadtime,hostname,participents) values (%s,%s,%s,%s,%s,%s)".format(audioFileType)

            #variable that holds data, which going to the database table
            data = (id,podcastName,duration,formatted_date,hostName,participents)
            
        elif audioFileType == "audiobook":
            #converting upcoming string into json(dict)
            audioMeta      = json.loads(audioMeta)
            id             = audioMeta["id"]
            title          = audioMeta["title"]
            author         = audioMeta["author"]
            narrator       = audioMeta["narrator"]
            duration       = audioMeta["duration"]
            dateTime       = datetime.datetime.utcnow()
            formatted_date = dateTime.strftime('%Y-%m-%d %H:%M:%S')

            #Query by which data inserted into data base
            query = "INSERT INTO {} (ID,title,author,narrator,duration,uploadtime) values (%s,%s,%s,%s,%s,%s)".format(audioFileType)

            #variable that holds data, which going to the database table
            data = (id,title,author,narrator,duration,formatted_date)

        #executing, commiting and closing all the objects
        myCursor.execute(query,data)
        mydb.commit()
        myCursor.close()
        mydb.close()

        #returning data and 200 Ok after successfully inserted data
        return "200 ok"

    except Exception as e:
        return str(e)