def LL_send_interactions(): mongo = current_app.mongo error = None session_id = get_session_id() token = request.args.get('token') interactionSession = mongo.db.interactionSessions.find_one({'_id': token}) if interactionSession: if interactionSession['userSession'] == session_id: interactions = json.loads( request.args.get('interactions') ) mongo.db.interactionSessions.update({'_id': token}, { '$pushAll': {'interactions': interactions} }) likes = [] for ts, evtType, tc, last_tc in interactions: if evtType == 'LIKE': likes.append(tc) if likes: mongo.db.userSessions.update({'_id': session_id}, { '$pushAll': {'likes.%s' % (interactionSession['videoId']): likes} }) else: error = 403 else: error = 404 return jsonify({'ok': 'ok'} if not error else {'error': error})
def dump_session(): mongo = current_app.mongo return jsonify({ "session['session_id']": get_session_id(), 'userSessions': list(mongo.db.userSessions.find()), 'interactionSessions': list(mongo.db.interactionSessions.find()), })
def LL_create_session(): token = generate_unique_token() videoId = request.args.get('videoId') ts = request.args.get('ts') session_id = get_session_id() mongo = current_app.mongo mongo.db.interactionSessions.insert({ '_id': token, 'videoId': videoId, 'ts': ts, 'interactions': [], 'userSession': session_id }) mongo.db.interactionSessions.ensure_index('videoId') mongo.db.interactionSessions.ensure_index('userSession') return jsonify({'token': token})
def index(): return "LikeLines Backend server. Your user session id: %s" % get_session_id()