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 progress_generator(thread_id):
     while True:
         status = redis_db.get(thread_id).decode("utf-8")
         if is_number(status):
             yield "data:" + status + "\n\n"
         else:
             return "data:" + status + "\n\n"
Beispiel #3
0
def check_admin_otp(entered_otp, phone):
    try:
        otp = redis_db.get(phone).decode('utf-8')
        if otp == entered_otp:
            return True
        return False
    except (InvalidRequestError, OperationalError):
        raise InvalidUsageError('sql connection or syntax is improper', 500)
Beispiel #4
0
def daily_weather_report(locations):

    daily_weather = []

    for location in locations:
        if redis_db.exists((location.lat, location.lng)):
            nh_weather_str = redis_db.get((location.lat, location.lng))
            nh_weather_dict = json.loads(nh_weather_str)
            daily_weather.append(nh_weather_dict)
    print "daily_weather in sun functions"
    return daily_weather
Beispiel #5
0
def daily_weather_report(locations):

    daily_weather = []

    for location in locations:
        if redis_db.exists((location.lat, location.lng)):
            nh_weather_str = redis_db.get((location.lat, location.lng))
            nh_weather_dict = json.loads(nh_weather_str)
            daily_weather.append(nh_weather_dict)
    print "daily_weather in sun functions"
    return daily_weather
Beispiel #6
0
def check_otp(entered_otp, phone):
    try:
        otp = redis_db.get(phone).decode('utf-8')
        user = User.query.filter_by(phone=phone).first()
        if otp == entered_otp:
            user.is_verified = 1
            db.session.commit()
        else:
            return make_response(jsonify({'response': "Invalid otp or expired otp"}), 400)
    except (InvalidRequestError, OperationalError):
        raise InvalidUsageError('sql connection or syntax is improper', 500)
Beispiel #7
0
def retrieve():
    key_values = {}
    for key in app.config["ACTIVE_ENVIRONMENTS"]:
        value = redis_db.get(key)
        if value:
            key_values[key] = json.loads(value)
        else:
            key_values[key] = {"environment": None, "jira_id": None}
    return app.response_class(response=json.dumps({"data": key_values}),
                              status=200,
                              mimetype="application/json")
Beispiel #8
0
def twilio_callback():
    to = request.form.get('To', '')
    from_ = request.form.get('From', '')
    message = request.form.get('Body', '').lower()
    if to == TWILIO_NUMBER:
        redis_db.incr(cgi.escape(message))
        socketio.emit('msg', {'div': cgi.escape(message),
                              'val': redis_db.get(message)},
                               namespace='/presentation')
    #resp = twiml.Response()
    #resp.message('Merci/Cheers.')
    return str(resp)
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 #10
0
 def status(self, task_id):
     status = redis_db.get(task_id)
     if not status:
         return None
     return json.loads(status)
Beispiel #11
0
def check_if_token_in_blacklist(decrypted_token):
    jti = 'jti.' + decrypted_token['jti']
    return bool(redis_db.get(jti))
Beispiel #12
0
 def test_redis_connection(self):
     redis_db.set('foo', 'bar')
     self.assertEqual(redis_db.get('foo'), 'bar')
     redis_db.delete('foo')
Beispiel #13
0
 def test_redis_connection(self):
     redis_db.set('foo', 'bar')
     self.assertEqual(redis_db.get('foo'), 'bar')
     redis_db.delete('foo')