Exemplo n.º 1
0
def admin_meta_blueprint():
    if only_admin() != None:
        return only_admin()

    bioform = BioForm(csrf_enabled=False)
    msg = ''

    if bioform.validate_on_submit():
        if get_option('bio') != None:
            get_option('bio').value = bioform.bio.data
        else:
            create_option('bio', bioform.bio.data)

        if get_option('bio_heading') != None:
            get_option('bio_heading').value = bioform.heading.data
        else:
            create_option('bio_heading', bioform.heading.data)

        sess.commit()
    else:
        if get_option('bio_heading') != None:
            bioform.heading.data = get_option('bio_heading').value

        if get_option('bio') != None:
            bioform.bio.data = get_option('bio').value

    return render_template('admin_meta.html', bioform=bioform, msg=msg)
Exemplo n.º 2
0
    def delete(self, data, token):
        user = sess.query(User).filter(User.id==data['id']).first()
        if user is not None:
            if user.token != token:
                return throw_error(400, 'Bad token')

            sess.delete(user)
            sess.commit()

            return throw_error(200, 'null')
        else:
            return throw_error(400, 'No such user')
Exemplo n.º 3
0
def register_blueprint():
    form = MyForm(csrf_enabled=False)
    msg = ''

    if form.validate_on_submit():

        if form.password.data != form.password_confirm.data:
            msg = 'Passwords does not match'
        else:
            if sess.query(User).filter(User.email==form.email.data).count() > 0:
                msg = 'This email is already registered'
            else:
                user = User(email=form.email.data, password=form.password.data)
                sess.add(user)
                sess.commit()

                msg = 'Thank you for registering'

    return render_template('register.html', form=form, msg=msg)
Exemplo n.º 4
0
def save_digits():
    post = parsePost(request.form)
    images_to_recognize_again = dict()

    # save manually recognized digits
    for digit_id, digit_val in post['result'].items():
        dbdigit = dgDigitById(digit_id)
        if dbdigit.result != digit_val[0]:
            images_to_recognize_again[dbdigit.image_id] = dbdigit.image
        dbdigit.result = digit_val[0]
        if 'use_for_training' in post and digit_id in post['use_for_training']:
            dbdigit.use_for_training = True
        else:
            dbdigit.use_for_training = False

    # identify saved images again
    for img_id, image in images_to_recognize_again.items():
        image.identifyDigits()

    sess.commit()
    return redirect(url_for('recognize'))
Exemplo n.º 5
0
def save_digits():
    post = parsePost(request.form)
    images_to_recognize_again = dict()
    
    # save manually recognized digits 
    for digit_id, digit_val in post['result'].items():
        dbdigit = dgDigitById(digit_id)
        if dbdigit.result!=digit_val[0]:
            images_to_recognize_again[dbdigit.image_id] = dbdigit.image        
        dbdigit.result = digit_val[0]
        if 'use_for_training' in post and digit_id in post['use_for_training']:
            dbdigit.use_for_training = True
        else:
            dbdigit.use_for_training = False
    
    # identify saved images again
    for img_id,image in images_to_recognize_again.items():
        image.identifyDigits()
            
    sess.commit()
    return redirect(url_for('recognize'))
Exemplo n.º 6
0
def admin_flickr_blueprint():
    if only_admin() != None:
        return only_admin()

    flickrform = FlickrForm(csrf_enabled=False)
    msg = ''

    if flickrform.validate_on_submit():
        get_option('flickr_api_key').value = flickrform.apikey.data
        get_option('flickr_api_secret').value = flickrform.apisecret.data
        get_option('flickr_farm').value = flickrform.farm.data
        get_option('flickr_user').value = flickrform.flickruser.data

        sess.commit()
    else:
        flickrform.apikey.data = get_option('flickr_api_key').value
        flickrform.apisecret.data = get_option('flickr_api_secret').value
        flickrform.farm.data = int(get_option('flickr_farm').value)
        flickrform.flickruser.data = get_option('flickr_user').value


    return render_template('admin_flickr.html', flickrform=flickrform)
if __name__ == '__main__':

    images, http = getImagesFromGDrive()

    print("opencv version: %s" % cv2.__version__)

    # Process each photo
    for img_info in images:

        img = createImageFromGDriveObject(img_info, http)
        file_name = img_info['title']

        mylogger.info("Process %s" % file_name)

        # create image object
        try:
            dbimage = getImage(os.path.basename(file_name))
            dbimage.img = img
            dbimage.download_url = img_info["downloadUrl"]
            dbimage.img_link = img_info['webContentLink'].replace(
                '&export=download', '')
        except ValueError as e:
            print e
            continue

        # try to recognize image
        if dbimage.identifyDigits():
            mylogger.info("Result is %s" % dbimage.result)

        sess.commit()
Exemplo n.º 8
0
def delete_option(key):
    sess.delete(get_option(key))
    sess.commit()
Exemplo n.º 9
0
def create_option(key, value):
    sess.add(Option(key=key, value=value))
    sess.commit()
Exemplo n.º 10
0
'''
 -- Gaz counter values recognizing

@author:     malefic
@contact:    [email protected]
'''

import re

from gdrive import downloadImageFromGDrive

from models import Image, sess, mylogger
        
if __name__ == '__main__':

    # fetch unrecognized images
    unrecognized_images = sess.query(Image).filter_by(result='').all()  
    for image in unrecognized_images:
        mylogger.info("Process %s" % image.file_name)
        # try to recognize digits using new training data
        m = re.search('id=(.*)', image.img_link)
        image.img = downloadImageFromGDrive(image.download_url, file_id=m.group(1))        
        image.identifyDigits()
    sess.commit()
    

    
    
    
    
    
Exemplo n.º 11
0
    def register(self, data, token):
        ids = []

        if 'users' not in data:
            return throw_error(422, 'JSON missing users array')

        for user in data['users']:

            existing_user = sess.query(User).filter(User.email==user['email']).first()
            if existing_user is not None:
                return throw_error(202, 'User already exists')

            try:
                u = User(\
                    firstname=user['firstname'],\
                    lastname=user['lastname'],\
                    email=user['email'],\
                    avatar_url=user['avatar_url'],\
                    password=encrypt(user['password']),\
                    master=user['master'],\
                    token=token
                )
            except KeyError:
                return throw_error(422, 'Invalid data')

            # Validating the password, is it equal to the confirmation password?
            if u.password != encrypt(user['password_confirm']):
                return throw_error(202, 'Passwords does not match!')

            # Validating each field of the user
            for attr, value in u.__dict__.items():
                if value is '' or value is ' ' or value is None:
                    return throw_error(422, 'Value of {attribute} is empty.'.format(attribute=attr))
            
            # adding user to database
            sess.add(u)

            # flushing the session
            sess.flush()

            # refreshing the user object to obtain the new id
            sess.refresh(u)

            # collecting the id of the user
            ids.append(u.id)

            # Adding custom_fields if there are any
            if 'custom_fields' in user:
                print(user['custom_fields'])
                for field in user['custom_fields']:

                    try:
                        customfield = CustomField(
                            key=field['key'],
                            value=field['value'], user_id=u.id\
                        )
                    except (TypeError, KeyError):
                        return throw_error(422, 'custom_fields is malformed')

                    sess.add(customfield)

            # Finally, we are saving the user
            sess.commit()

        return {'status' : 201, 'ids' : ids, "errors" : None}
Exemplo n.º 12
0
def remove_admin(id):
    get_user(id).admin = 0
    sess.commit()
Exemplo n.º 13
0
def make_admin(id):
    get_user(id).admin = 1
    sess.commit()
Exemplo n.º 14
0
def unregister(id):
    sess.delete(get_user(id))
    sess.commit()