Пример #1
0
def dataPost(image, clean_score=-1):
    '''Posts a valid input to database, receives image binary and optionally a value for 'clean_score'  

    This method is currently INVALID, it will not work properly'''
    return None
    con = shared.setupDatabase()
    cur = con.cursor()
    cur.execute("insert into images(image) values (?)",
                ([sqlite3.Binary(image)]))
    if clean_score != -1:
        clean_score = int(clean_score)
        cur.execute(
            "update images set clean_score=? where id=(select max(id) from images)",
            (clean_score, ))

    con.commit()
    return 'success'
Пример #2
0
def dataPut(stuff):
    con = shared.setupDatabase()
    cur = con.cursor()
    possible_values = ['cupboards_open']

    if 'data' in stuff:
        updates = stuff['data']
        for update in updates:
            allUpdates = {}
            if ('id' in update and 'changes' in update):
                changes = update['changes']
                for value in changes:
                    # https://stackoverflow.com/questions/38420829/variable-column-name-in-sql-lite-and-python
                    cur.execute(
                        'update images set {} = ? where id = ?'.format(value),
                        (int(changes[value]), int(update['id'])))
    else:
        abort(400)
    con.commit()

    return "success"
Пример #3
0
def dataGet(stuff):
    ''' gets a list of all the images in the db '''
    con = shared.setupDatabase()
    cur = con.cursor()
    cur.execute('select * from images')
    return json.dumps(cur.fetchall())