diff --git a/recommendation_engine.py b/recommendation_engine.py index 023bbe4..f2a14d7 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -78,6 +78,7 @@ class Engine: return clips def get_videos(self, user): + user = kwargs['user'] channels = {k: v.get('value', 0) for k, v in self.state['channels'].items()} sliders = {k: v.get('value', 0) for k, v in self.state['globalKeywords'].items()} # For each playlist, compute user keyword score @@ -131,6 +132,10 @@ class Engine: 'tags': video['tags'], } for video in videos] + def get_next(self, user, position): + video = self.get_videos(user)[position] + return video + def update_state(self, data): for key in data: if key in self.state: diff --git a/server.py b/server.py index 84176f3..5a77517 100755 --- a/server.py +++ b/server.py @@ -27,7 +27,9 @@ logger = logging.getLogger(__name__) def api_task(request, engine, callback): try: if request['method'] == 'getVideos': - result = engine.get_videos(request['params']) + result = engine.get_videos(**request['params']) + elif request['method'] == 'getNext': + result = engine.get_next(**request['params']) elif request['method'] == 'getRecommendations': result = engine.state elif request['method'] == 'setRecommendations':