Example #1
0
def index():
    notes = None
    if current_user.is_authenticated:
        if not redis_client.exists(f'{current_user.id}:notes_id'):
            notes = current_user.notes.order_by(Note.edit_date.desc())
            if notes.count() != 0:
                for note in notes:
                    note_dict = NoteConverter.note_to_dict(note)
                    redis_client.lpush(f'{current_user.id}:notes_id',
                                       note_dict['id'])
                    redis_client.hmset(note_dict['id'], note_dict)
                flash('Your notes where loaded from postgresql !', 'info')
            else:
                notes = None
        else:
            notes = []
            count = 0
            while count < redis_client.llen(f'{current_user.id}:notes_id'):
                note_id = redis_client.lindex(f'{current_user.id}:notes_id',
                                              count)
                notes.append(
                    NoteConverter.dict_to_note(redis_client.hgetall(note_id)))
                count += 1
            flash('Your notes where loaded from redis !', 'info')
    return render_template("index.html", title='Your notes', notes=notes)
Example #2
0
def reset_threshold():
    pipes = {
        "WPA-H2O-pot-out", "WPA-H2O-in-CO2", "WPA-H2O-in-CDRA",
        "WPA-H2O-in-SRA", "SRA-H2O-out", "SRA-H2-in", "SRA-CH4-out",
        "SRA-N2-in", "OGA-O2-out", "OGA-H2-out", "OGA-H2O-pot-in",
        "CDRA-H2O-out", "CDRA-CO2-out"
    }
    for pipe in pipes:
        redis_client.hset("threshold", pipe, "10000")
    pipe_thresh_dict = redis_client.hgetall("threshold")
    print('threshold', pipe_thresh_dict)
Example #3
0
def test():
    id = request.args.get('id')
    name = request.args.get('name')
    age = request.args.get('age')
    dic = {
        'age': age,
        'name': name,
        'id': id,
        'address': {
            "1": 1,
            "province": 13,
            "city": 3
        }
    }
    redis_client.hmset('user_info', dic)
    re = redis_client.hmget('user_info', 'name', 'age')
    all = redis_client.hgetall('user_info')
    print(all)
    return jsonify(data=all)
Example #4
0
def process_property_listing_images(redis_img_dict_key):
    """
    Resize the image file using the PIL image library and save it to the app server or
    Amazon S3 depending on the configuration. Since a property listing has many images, a
    directory is created with redis_img_dict_key as the directory name where the image files
    are saved.
    """
    temp_image_path = Path(
        f"{current_app.root_path}/base/static/{temp_image_dir}")
    redis_images = redis_client.hgetall(redis_img_dict_key)
    folder_to_save_image = Path(
        f"{current_app.root_path}/base/static/{property_listing_images_dir}{redis_img_dict_key}"
    )
    folder_to_save_image.mkdir(parents=True, exist_ok=True)

    for image_filename in redis_images.keys():
        image_filename = image_filename.decode("utf-8")
        image_file = redis_client.hget(redis_img_dict_key, image_filename)
        image_obj = Image.open(io.BytesIO(image_file))
        image_obj.thumbnail((800, 800))
        image_obj.save(
            f"{current_app.root_path}/base/static/{temp_image_dir}{image_filename}"
        )

        if image_server_config == "app_server_storage":
            shutil.copyfile(
                f"{temp_image_path}/{image_filename}",
                f"{folder_to_save_image}/{image_filename}",
            )
            os.remove(
                f"{temp_image_path}/{image_filename}"
            )  # Clean up by deleting the image in the temporary folder
            redis_client.hdel(
                redis_img_dict_key,
                image_filename)  # Clean up by deleting the image in redis
        elif image_server_config == "amazon_s3":
            # Upload the image to Amazon S3 if the configuration is set to "amazon_s3"
            property_image_upload_to_S3.delay(image_filename,
                                              redis_img_dict_key)
Example #5
0
def piping():
    error = None
    #is this the first time to this page and came from scenario?
    url = request.referrer
    if "scenario" in url:
        #set initial time for countdown timer
        session['starttime'] = time.time()
        #place times into redis for retrival by a different browser
        redis_client.set("starttime", time.time())
        redis_client.set("scenariotime", session.get("scenario_time"))

        if (int(session.get("scenario_time")) == 0):
            return redirect(url_for('scenario'))
        else:
            countdown = (session.get("scenario_time")) * 60

    else:
        #account for time elapsed since countdown started
        elapsed_time = (time.time()) - (session.get('starttime'))
        countdown = (session.get("scenario_time")) * 60 - elapsed_time
        if request.method == 'POST':
            pipe_data = request.form
            for key, value in pipe_data.items():
                if value:  #was a value entered in the field?
                    if not isInteger(value):
                        flash('correct your error and RESUBMIT')
                        error = " Threshold value must be an integer "
                    else:
                        print("threshold", key, value)
                        redis_client.hset("threshold", key, value)

    pipe_thresh = redis_client.hgetall("threshold")
    return render_template('piping.html',
                           title='Piping',
                           countdown=countdown,
                           error=error,
                           pipe_thresh=pipe_thresh)
Example #6
0
def get_ad(ad_id):
    ad_dict = redis_client.hgetall(KEY_SPACE_AD + str(ad_id))
    return Ad(ad_dict) if ad_dict else None
Example #7
0
def get_ads():
    return [
        Ad(redis_client.hgetall(KEY_SPACE_AD + ad_id))
        for ad_id in redis_client.smembers('ad_ids')
    ]