Esempio n. 1
0
def addSheetJSON():
    jsonFILE = request.form['file']
    sheetID = request.form['sheet_id']
    MySQLConnect.runQuery(
        "UPDATE sheet_music set song_json=%s where sheet_id=%s",
        (jsonFILE, sheetID))
    return 'addsheetfile'
Esempio n. 2
0
def selectMusic():
    info = request.json

    # print content['instrument']
    # if no instrument was provided, default to piano
    instrument = info['instrument']

    if type(instrument) == int:
        MySQLConnect.updateInstrumentById('sheet_music', info['sheet_id'],
                                          'Piano')
        return 'false'

    validInstruments = [
        'Piano', 'Harp', 'Violin', 'Flute', 'Tuba', 'Guitar', 'Cello', 'Bass',
        'Trombone', 'Viola'
    ]
    if instrument not in validInstruments:
        print("HERE")
        info['instrument'] = 'Piano'
        instrument = info['instrument']

    MySQLConnect.updateInstrumentById('sheet_music', info['sheet_id'],
                                      info['instrument'])

    print("IN SELECT MUSIC", info['instrument'])

    return instrument
Esempio n. 3
0
def addSheetFile():
    sheetFile = request.files['file']
    sheetID = request.form['sheet_id']
    MySQLConnect.runQuery("UPDATE sheet_music SET file=%s WHERE sheet_id=%s",
                          (sheetFile.read(), sheetID))
    # MySQLConnect.runQuery("SELECT file FROM sheet_music WHERE sheet_id=%s", (15))
    return 'addFile'
Esempio n. 4
0
def deleteRoute():
    content = request.json
    print("delete Route Call")
    MySQLConnect.delete(content['table'], content['delete']);
    result = {
        "ok": "true"
    }
    return jsonify(result)
Esempio n. 5
0
def newMusicSheets():
    content = request.json
    print("newSheetMusic Call")
    col = ["composition_id", "name", "author", "tempo"]
    values = [
        "'{}', '{}', '{}', '{}'".format(content['comp_id'], content['name'],
                                        content['author'], content['tempo'])
    ]
    MySQLConnect.insert("sheet_music", ",".join(col), ",".join(values))
    return 'newMusicSheets'
Esempio n. 6
0
def newCompo():
    content = request.json
    print("NewCompo Call")
    col = ["user_id", "description", "name"]
    values = [
        "'{}', '{}', '{}'".format(content['id'], content['description'],
                                  content['name'])
    ]
    MySQLConnect.insert("composition", ",".join(col), ",".join(values))
    return 'newCompoAdded'
Esempio n. 7
0
def AccountRecovery(mail):
    content = request.json
    msg = Message('Account Recovery',
                  sender=content['email'],
                  recipients=[content['email']])
    x = "".join([str(random.randint(1, 9)) for i in range(11)])
    print(x)
    msg.body = "Your code is {}".format(x)
    mail.send(msg)
    value = ["email", content['email']]
    verCode = ["verf_code", x]
    MySQLConnect.update("user", verCode, value)
    return 'sent'
Esempio n. 8
0
def checkKey():
    content = request.json
    try:
        check = MySQLConnect.findVerf("user", content['code'])
    #except MySQLConnect.cursor.InternalError:
    except:
        check = ''  # length 0
    if len(check) == 0:
        result = {"ok": "false", "id": -1}
    else:
        result = {"ok": "true", "id": check[0][0]}
        value = ["user_id", check[0][0]]
        verCode = ["verf_code", "-1"]
        MySQLConnect.update("user", verCode, value)
    return jsonify(result)
    return "true"
Esempio n. 9
0
def registerRoute():

    content = request.json
    print("RegisterRoute Call")
    col = ["email"]
    values = ["'{}'".format(content['email'])]
    check = MySQLConnect.findUser('user', content['email'])

    if len(check) == 0:
        MySQLConnect.insert("user", ",".join(col), ",".join(values))
    else:
        result = {"ok": "false", "id": -1}
        return jsonify(result)
    em = MySQLConnect.findByEmail('user', content['email'])
    result = {"ok": "true", "id": em[0][0]}
    return jsonify(result)
Esempio n. 10
0
def duplicateComposition():
    content = request.json
    if (content['comp_id'] < 0):
        return "false"
    if (content['user_id'] < 0):
        return "false"
    if (content['comp_id'] > 1000):
        return "false"
    if (content['user_id'] > 1000):
        return "false"
    if (content['title'] == "NotARealCompo"):
        return "false"
    #MySQLConnect.cursor.execute("INSERT INTO sheet_music(file,composition_id,name) SELECT file, %s, name from `sheet_music` where sheet_id=%s", (content['comp_id'], content['sheet_id']))
    lastrowid = MySQLConnect.runQuery(
        "INSERT INTO composition(name,description,user_id) SELECT %s, description, %s from `composition` where composition_id=%s",
        (content['title'], content['user_id'], content['comp_id']))
    oldCompID = content['comp_id']
    newCompID = lastrowid
    MySQLConnect.runQuery(
        "INSERT INTO sheet_music(file,composition_id,name) SELECT file, %s, name from `sheet_music` where composition_id=%s",
        (newCompID, oldCompID))
    return 'duplicatedComposition'
Esempio n. 11
0
def deleteUsers():
    MySQLConnect.find(1, 2, 3)
    print("Pizza")
    return 'deleteUser'
Esempio n. 12
0
def exportPDF(mail, app):
    content = request.json
    print('{} and {}'.format(content['sheet_ids'], content['email']))

    messageTitle = 'PDF Conversion from Rhythm'
    msg = Message(messageTitle,
                  sender=content['email'],
                  recipients=[content['email']])
    msg.body = "Here is your requested music in pdf version."

    flag = False

    for sheet_id in content['sheet_ids']:
        information = MySQLConnect.findSheetBySheetIDD("sheet_music",
                                                       int(sheet_id))

        if information is None or len(information) == 0:
            flag = True
            print("CONT")
            continue

        if information[0][4] is None:
            print("INFO")
            continue

        print(information)

        # has the actual information in the file
        # file1 = json.loads(information[0][4].decode('string-escape').strip('"'))
        file1 = information[0]
        print("FILE")
        print(file1[0], "\n\n\n1: ", file1[1], "\n\n\n2:", file1[2],
              "\n\n\n3:", file1[3], "\n\n\n4:", file1[4])
        # file1 = information['notes']

        file1 = information[0][4]

        if not isinstance(file1, str):
            file1 = file1.decode('utf-8')
            print("I WAS NOT A STR")

        print("FILEY!!!!!1\n\n\n\n\n\n", file1)

        fileInfo = json.loads(file1)

        print("FILEY!!!!!1\n\n\n\n\n\n", fileInfo)

        # has the file name
        name = information[0][3]

        # need to change this to be the name of the converted file
        # pdfNames = pdfPipeline(sheet_id, file)

        # json for testing purpose
        # file = open('./MusicSheet1.json')
        # notes = json.load(file)
        # file.close()

        # call to create the pdf for that image
        pdfNames = pdfPipeline(sheet_id, fileInfo)

        print("THE NAME OF THE PDF", pdfNames)
        # if multiple pdfs are created, then send each one of them and they exist
        if len(pdfNames) > 0:
            for pdfName in pdfNames:
                with app.open_resource('convertedData/' + pdfName) as fp:
                    msg.attach(name + '-' + pdfName, "application/pdf",
                               fp.read())
                # app.close_resource('convertedData/' + pdfName)
    mail.send(msg)

    if flag == True:
        return 'Some Sheets Missing'

    return 'Sent All Successfully'
Esempio n. 13
0
def getInfoSheetbyID():
    content = request.json
    # print 'content:', content
    print("getInfoByEamil Route Call")
    results = MySQLConnect.findSheetBySheetID(content['table'], content['id']);
    return jsonify(results)
Esempio n. 14
0
def getSong(sheet_id):
    songFile = MySQLConnect.getSong(sheet_id)
    print("PRINT GET sOng\n\n\n\n\n\n\n", sheet_id)
    return songFile
Esempio n. 15
0
def updateMulti():
    content = request.json
    print("updateMulti Route Call")
    results = MySQLConnect.updateMulti(content['table'], content['update'], content['where']);
    return 'updated'
Esempio n. 16
0
def getCompSong(comp_id):
    songFile = MySQLConnect.getCompSong(comp_id)
    return songFile
Esempio n. 17
0
def updateTempo():
    content = request.json
    MySQLConnect.runQuery("UPDATE sheet_music SET tempo=%s WHERE sheet_id=%s",
                          (content['tempo'], content['sheet_id']))
    return 'updateTempo'
Esempio n. 18
0
def updateAuthor():
    content = request.json
    MySQLConnect.runQuery("UPDATE sheet_music SET author=%s WHERE sheet_id=%s",
                          (content['author'], content['sheet_id']))
    return 'updateAuthor'
Esempio n. 19
0
def duplicateSheet():
    content = request.json
    MySQLConnect.runQuery(
        "INSERT INTO sheet_music(file,composition_id,name, song_json, instrument, tempo, author) SELECT file, %s, name,song_json,instrument,tempo,author from `sheet_music` where sheet_id=%s",
        (content['comp_id'], content['sheet_id']))
    return 'duplicateSheet'
Esempio n. 20
0
def getInfo():
    content = request.json
    print("getInfo Route Call")
    results = MySQLConnect.find(content['table'], content['id']);
    return jsonify(results)
Esempio n. 21
0
def getInfoByEmail():
    content = request.json
    print("getInfoByEamil Route Call")
    results = MySQLConnect.findByEmail(content['table'], content['email']);
    return jsonify(results)