Esempio n. 1
0
def show_route_stops(route_id):
    """
    List all stops on route.
    """
    # TODO: add pagination

    cache_key = f'route_{route_id}'

    routes = redis.get('routes')

    if not routes:
        routes = transport.get_all_routes()
        # cache
        redis.set('routes', json.dumps(routes))
    else:
        routes = json.loads(routes.decode())

    route = routes.get(route_id)

    if cache_key.encode() in redis.keys():
        route_stops = json.loads(redis.get(cache_key).decode())
    else:
        route_stops = transport.get_route_stops(route_id)
        # store to cache
        redis.set(cache_key, json.dumps(route_stops))

    if current_user.is_authenticated:
        user_stops = [stop.code for stop in current_user.stops]
    else:
        user_stops = list()

    return render_template('route_stops.html',
                           route=route,
                           stops=route_stops,
                           user_stops=user_stops)
Esempio n. 2
0
def session_check(text=None):
    sid = request.cookies.get('sid', None)
    user = User.get_by_login('qwe')
    uid = user and user.id or None
    if sid and uid:
        session = {'user': {'id': uid}}
        redis.set(sid, pickle.dumps(session))
        return True
Esempio n. 3
0
def logout():
    sid = request.cookies.get('sid', None)
    session = redis.get(sid)
    if session is not None:
        session = pickle.loads(session)
        user = session.get('user', None)
        if user:
            user['id'] = None
            redis.set(sid, pickle.dumps(session))
Esempio n. 4
0
def logout():
    sid = request.cookies.get('sid', None)
    session = redis.get(sid)
    if session is not None:
        session = pickle.loads(session)
        user = session.get('user', None)
        if user:
            user['id'] = None
            redis.set(sid, pickle.dumps(session))
Esempio n. 5
0
def login(login, password):
    if ldap.bind_user(login, password):
        sid = request.cookies.get('sid', None)
        user = User.get_by_login(login)
        uid = user and user.id or None
        if sid and uid:
            session = {
                'create_datetime': datetime.datetime.now().isoformat(),
                'user': {'id': uid}
            }
            redis.set(sid, pickle.dumps(session))
            return True
    return False
Esempio n. 6
0
def login(login, password):
    if ldap.bind_user(login, password):
        sid = request.cookies.get('sid', None)
        user = User.get_by_login(login)
        uid = user and user.id or None
        if sid and uid:
            session = {
                'create_datetime': datetime.datetime.now().isoformat(),
                'user': {
                    'id': uid
                }
            }
            redis.set(sid, pickle.dumps(session))
            return True
    return False
Esempio n. 7
0
def show_all_routes():
    """
    List all routes.
    """
    # TODO: add pagination

    routes = redis.get('routes')

    if not routes:
        routes = transport.get_all_routes()
        # cache
        redis.set('routes', json.dumps(routes))
    else:
        routes = json.loads(routes.decode())

    return render_template('routes.html', routes=routes)
Esempio n. 8
0
def monitor_stop(stop_code):
    """
    Get info about certain stop.
    """
    stops = redis.get('stops')

    if not stops:
        stops = transport.get_all_stops()
        redis.set('stops', json.dumps(stops))
    else:
        stops = json.loads(stops.decode())

    stop = stops.get(stop_code)
    stop_info = transport.monitor_stop(stop_code)

    return render_template('stop_info.html', stop=stop, stop_info=stop_info)
Esempio n. 9
0
def user_log(room, uid, content):
    query = {"_id": room}
    user = User.query.get(uid)
    if user is None:
        message = {
            "errno": status.CODE_NO_USER,
            "errmsg": errmsg.user_not_exists,
        }
        socketio.emit("login_response",
                      message,
                      namespace="/mofang",
                      room=room)
        return

    name = user.nickname if user.nickname else user.name
    message = {
        "uid":
        user.id,
        "sid":
        request.sid,
        "user":
        name,
        "avatar":
        user.avatar if user.avatar else current_app.config["DEFAULT_AVATAR"],
        'created_time':
        int(datetime.now().timestamp()),
    }
    if "%s" in content:
        message["log"] = content % name
    else:
        message["message"] = content

    chat_list = mongo.db.user_chat_list.find_one(query)
    if not chat_list:
        mongo.db.user_chat_list.insert_one(query, {"stream_name": room})

    key = "%s_%s" % (room, request.sid)
    print(key)
    redis.set(key, user.id)
    mongo.db.user_chat_list.update_one(query,
                                       {"$push": {
                                           "message_list": message
                                       }})
    return message
Esempio n. 10
0
def show_all_stops():
    """
    List all stops.
    """
    # TODO: add pagination

    stops = redis.get('stops')

    if not stops:
        stops = transport.get_all_stops()
        redis.set('stops', json.dumps(stops))
    else:
        stops = json.loads(stops.decode())

    if current_user.is_authenticated:
        user_stops = [stop.code for stop in current_user.stops]
    else:
        user_stops = list()

    return render_template('stops.html', stops=stops, user_stops=user_stops)
Esempio n. 11
0
def translate_video_title(what):
	to_language = g.lang_code

	if to_language == "en":
		return what

	key = "{0}_{1}".format(what, to_language)

	translation = redis.get(key)

	if translation:
		return translation

	translator = Translator(to_lang=to_language)
	
	try:
		translation = translator.translate(what)
		redis.set(key, translation)
	except:
		translation = what

	return translation
Esempio n. 12
0
def touch(sid, session):
    session['touch_datetime'] = datetime.datetime.now().isoformat()
    redis.set(sid, pickle.dumps(session))
Esempio n. 13
0
 def delete(self):
     jti = get_raw_jwt()["jti"]
     redis.set(jti, "true", app.config["JWT_ACCESS_TOKEN_EXPIRES"] * 1.2)
     return {"message": "Access token revoked successfully"}
Esempio n. 14
0
def touch(sid, session):
    session['touch_datetime'] = datetime.datetime.now().isoformat()
    redis.set(sid, pickle.dumps(session))