예제 #1
0
파일: views.py 프로젝트: kadr/simbir_soft
def index():
    keys: list = redis.keys(f'{current_user.id}_*')
    data: list = []
    for key in keys:
        data.append(json.loads(redis.get(key)))

    return render_template('blog/index.html', data=data if data is not None else [])
예제 #2
0
def daily_rate(currency):
    currency = currency.lower()
    if currency not in AVAILABLE_CURRENCY_UNITS:
        return 'Lutfen gecerli bir para birimi giriniz'

    redis_keys_for_daily = redis.keys(pattern='daily_*')
    daily_values = fill_values(redis_keys_for_daily)
    lowest_daily_rate = compare_daily_rate(daily_values)
    if len(lowest_daily_rate):
        return json.dumps(lowest_daily_rate[currency])
    return 'Gunluk veri bulunamadi'
예제 #3
0
def search_by_code():
    """
    根据 operator_code 查询数据
    :return:
    """
    data = redis.keys()
    debug(data)
    operator_code = request.values.get("operator_code", 0)
    if operator_code == 0:
        return Reply.error("failed")
    data = redis.get("op_{operator_code}".format(operator_code=operator_code))
    return Reply.error("empty") if data is None else Reply.success(
        [{
            "operator_code": operator_code,
            "config": data
        }])
def edit_organization():
    current_org = get_jwt_identity()

    # check if already in database
    exists = Organization.query.filter_by(email=current_org).first()

    if exists:
        password = request.form.get('password')
        if password:
            salt, hashed_password = secure_password(password)
            exists.password = hashed_password
            exists.salt = salt

        exists.phone_number = request.form.get('phone_number')
        exists.organization_website = request.form.get('organization_website')
        exists.organization_name = request.form.get('organization_name')
        exists.organization_description = request.form.get('organization_description')
        exists.organization_street_address = request.form.get('organization_street_address')
        exists.organization_city = request.form.get('organization_city')
        exists.organization_state = request.form.get('organization_state')
        exists.organization_country = request.form.get('organization_country')
        exists.organization_type = request.form.get('organization_type')

        if request.form.get('year_established'):
            exists.year_established = request.form.get('year_established')

        db.session.commit()

        for i in redis.keys():
            data = pickle.loads(redis.get(i))
            for j in data:
                if j['organization_id'] == current_org:
                    redis.delete(i)
                    break

        return jsonify("Success")
    else:
        return jsonify("Organization Does Not Exist")
예제 #5
0
def run_game(game_id):
    tv_mode = request.args.get('mode') == "tv"
    key = "{}|*".format(game_id)
    keys = redis.keys(key)
    if len(keys) >= 4:
        flash("This game is full, start a new one", "errors")
        return redirect(url_for('main.index'))
    form = GameForm()
    if form.validate_on_submit():
        session['nickname'] = form.data["nickname"]
        session['handle'] = form.data["handle"]
        if not redis.exists(form.data["game_id"]):
            impact_map = ImpactMap()
            impact_map.initialize()
            redis.set(form.data["game_id"], json.dumps(impact_map.impact_map))
        return redirect("/{}".format(game_id))

    if tv_mode:
        return render_template(
            'tv.html',
            game_id=game_id
        )

    if 'nickname' in session and len(keys) > 0:
        try:
            with open("initial-code.txt") as f:
                initial_code = f.read()
        except IOError:
            initial_code = "function main() {" + os.linesep + "}"
        return render_template(
            'game.html',
            game_id=game_id,
            nickname=session["nickname"],
            handle=session["handle"],
            initial_code=initial_code
        )
    else:
        return render_template('setup.html', game_id=game_id, form=form)
예제 #6
0
파일: views.py 프로젝트: wodim/wpsc
def check(guid):
    if not is_valid_guid(guid):
        abort(400)

    # request ongoing?
    status = redis.get(redis_key('%s.%s' % (guid, 'status')))
    if status is None:
        abort(500) # this should not happen, unless load average is too high

    # error occured?
    if status == 'error':
        return jsonify(status='error')
    elif status == 'processing':
        percent = redis.get(redis_key('%s.%s' % (guid, 'percent')))
        return jsonify(status='processing', percent=percent)
    elif status == 'done':
        results = {}
        for key in redis.keys('%s.*' % (redis_key(guid),)):
            if key not in ['%s.status' % (redis_key(guid),), '%s.percent' % (redis_key(guid),)]:
                results[key] = redis.hgetall(key)

        return jsonify(status='done', results=render_template('table.html', results=results))

    abort(500) # is this even possible?
예제 #7
0
def recent_product():
    keys_alive = redis.keys("product-*")
    products = [redis.get(k).decode("utf-8") for k in keys_alive]
    return jsonify({'products': products})
예제 #8
0
def clear_cache():
    for i in redis.keys():
        redis.delete(i)
예제 #9
0
def get_redis_keys():
    return str(redis.keys('*'))
예제 #10
0
def send_notification(args):
    print(args)
    print(redis.keys('*'))
def get_device_data_from_redis():
    prefix = current_app.config.get("ES_KEY_PREFIX", "zeus_cmdb_device_info:")
    device_data_keys = redis.keys(prefix + "*")
    for key in device_data_keys:
        device_data = redis.get(key)
        yield device_data
예제 #12
0
def check():
    for key in redis.keys('*'):
        for data in redis.smembers(key):
            data = data.decode('utf-8')
            scrap(json.loads(data))