Beispiel #1
0
def create_contactsheet():

    form = NewContactsheetForm()
    thread_id = current_user.get_id()

    redis_db.set(thread_id, "0")
    if form.validate_on_submit():
        upload_thread = Upload_thread(form, current_user.get_id(), thread_id)
        upload_thread.start()

        while True:
            status = redis_db.get(thread_id).decode("utf-8")
            if is_number(status):
                if float(status) >= 100.0:
                    flash("Successfully created contact sheet", "message")
                    return redirect(url_for("index"))
                else:
                    time.sleep(0.2)
            else:
                flash(redis_db.get(thread_id).decode("utf-8"), "error")
                return redirect(url_for("index"))

    return render_template("/create.html",
                           form=form,
                           max_file_size=size_of(Config.FILE_SIZE_LIMIT),
                           thread_id=thread_id)
Beispiel #2
0
def index():
    response = None
    data = json.loads(request.data)

    # Ensure the correct data is sent in
    if not data.get("url"):
        return make_response(("'url' data field is required", 400))
    if not data.get("expected_status"):
        return make_response(("'expected_status' data field is required", 400))

    redis_db.set(data.get("url"), data.get("expected_status"))

    return make_response(("Added key/value pair", 201))
Beispiel #3
0
def update():
    data = json.loads(request.data)
    environment = data.get("environment")
    branch = data.get("branch")
    jira_id = data.get("jira_id")

    # Ensure the correct data is provided in
    if not environment or not branch:
        return app.response_class(
            response=json.dumps({
                "title": "missing parameters",
                "message":
                "Both 'environment' and `branch` fields are required",
                "status:": 400,
            }),
            status=400,
            mimetype="application/json",
        )

        return make_response()

    if environment not in app.config["ACTIVE_ENVIRONMENTS"]:
        return app.response_class(
            response=json.dumps({
                "title":
                "invalid environment",
                "message":
                "'environment' must be one of the following: {}".format(
                    ",".join(app.config["ACTIVE_ENVIRONMENTS"])),
                "status:":
                400,
            }),
            status=400,
            mimetype="application/json",
        )

    redis_db.set(environment, json.dumps({
        "branch": branch,
        "jira_id": jira_id
    }))
    return app.response_class(
        response=json.dumps({
            "data":
            "{} marked in used by {}".format(environment, branch),
            "status:":
            201
        }),
        status=201,
        mimetype="application/json",
    )
Beispiel #4
0
def cache_rows():
    while not QUIT:
        next = redis_db.zrange('schedule:', 0, 0, withscores=True)
        now = time.time()
        if not next or next[0][1] > now:
            time.sleep(.05)
            continue

        row_id = next[0][0]

        # 延迟为 0 视为删除
        delay = redis_db.zscore('delay:', row_id)
        if delay <= 0:
            redis_db.zrem('delay:', row_id)
            redis_db.zrem('schedule:', row_id)
            redis_db.delete('inv:' + row_id)
            continue

        row = Inventory.get(row_id)
        redis_db.zadd('schedule:', row_id, now + delay)
        redis_db.set('inv:' + row_id, json.dumps(row.to_dict()))
def seed_daily_weather():

    lat = 37.7655
    lng = -122.4429
    exp_time = 36000

    # pull coordinates from local db
    neighborhoods = Location.query.limit(10)

    # run api on each coordinate
    for nh in neighborhoods:

        forecast = app.weather_forecast.Weather.get_forecast(nh.lat, nh.lng, None, nh.n_hood)

        range_temp = forecast.high_F + u'\xb0F' +'-' + forecast.low_F + u'\xb0F'
        img_url = forecast.pic

        weather_id = (nh.lat, nh.lng)
        weather_details = { 'lat': nh.lat, 'lng': nh.lng, 'img_url': img_url ,'temp_range':range_temp }

        # store coord id and hash of weather details
        redis_db.set(weather_id, json.dumps(weather_details), exp_time)

        print redis_db.get(weather_id)
Beispiel #6
0
 def _save(self):
     message = {"job_id": self.job_id, "status": self.status}
     if self.errors:
         message["error"] = self.errors
     redis_db.set(self.job_id, json.dumps(message))
 def test_redis_connection(self):
     redis_db.set('foo', 'bar')
     self.assertEqual(redis_db.get('foo'), 'bar')
     redis_db.delete('foo')
Beispiel #8
0
 def test_redis_connection(self):
     redis_db.set('foo', 'bar')
     self.assertEqual(redis_db.get('foo'), 'bar')
     redis_db.delete('foo')
Beispiel #9
0
else:
    # 根据数据库配置修改scheduler计划, 用户覆盖默认配置文件中的配置
    # SchedulerControl.scheduler_modify()
    pass

# 初始化摄像头
logger.info('Start to init hik sdk')
init_flag = False
try:
    assert do_init(), "sdk初始化失败"
    assert init_overtime(), "初始化超时时间失败"
    assert register_callback(), "注册回调函数失败"
    init_flag = True
except Exception as e:
    logger.error(e)
    redis_db.set('hardware_sdk_init_status', 0)

# 登陆摄像头并且布防
if init_flag:
    try:
        assert login_camera(), "登陆摄像头失败"
        # 布防并且配置道闸参数
        lUserIDs = set_alarm()
        if not lUserIDs:
            logger.error("布防失败")
            redis_db.set('hardware_sdk_work_status', 0)
        else:
            redis_db.set('hardware_sdk_work_status', 1)
    except Exception as e:
        logger.error(e)
        redis_db.set('hardware_sdk_work_status', 0)
Beispiel #10
0
def store_access_token(user, token):
    try:
        redis_db.set(user, token)
        redis_db.expire(user, 1000)
    except Exception:
        raise InvalidUsageError('encoding error,try again', 500)
Beispiel #11
0
def store_otp(phone, otp):
    try:
        redis_db.set(phone, otp.encode('utf-8'))
        redis_db.expire(phone, 1800)
    except Exception:
        raise InvalidUsageError('encoding error,try again', 500)