def get(self): """Get a list of all available channels.""" with session_scope() as session: channel_list = db_calls.get_channel_list(session) return flask.make_response( flask.jsonify(auxiliary.list_to_json(channel_list)), 200)
def put(self, args): """Update a reminder.""" reminder_id = args['reminder_id'] anticipation_minutes = args['anticipation_minutes'] with session_scope() as session: # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') success, msg = reminders.update_reminder(session, reminder_id, anticipation_minutes, user_id) if success: return flask.make_response( flask.jsonify({ 'reminder_list': auxiliary.list_to_json( reminders.get_reminders(session, user_id)) }), 201) else: if msg == 'Not found': return flask.make_response('', 404) else: return flask.make_response(msg, 400)
def post(self, args): """Register an alarm.""" show_name = args['show_name'] is_movie = args['is_movie'] alarm_type = args['type'] trakt_id = None show_season = None show_episode = None for k, v in args.items(): if v is None: continue if k == 'show_season': show_season = v elif k == 'show_episode': show_episode = v elif k == 'trakt_id': trakt_id = v with session_scope() as session: try: alarm_type = AlarmType[alarm_type] except KeyError: return flask.make_response('Invalid Alarm Type', 400) # Alarms for Listings are no longer valid if alarm_type == AlarmType.LISTINGS: return flask.make_response('Invalid Alarm Type', 400) if alarm_type == AlarmType.DB and trakt_id is None: return flask.make_response('Missing Trakt Id', 400) if not is_movie and (show_season is None or show_episode is None): return flask.make_response('Missing Season Episode', 400) # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') if db_calls.register_alarm(session, show_name, trakt_id, is_movie, alarm_type, show_season, show_episode, user_id) is not None: return flask.make_response( flask.jsonify({ 'alarm_list': auxiliary.list_to_json( processing.get_alarms(session, user_id)) }), 201) else: return flask.make_response('Alarm Already Exists', 400)
def get(self): """Get the list of alarms of the user.""" with session_scope() as session: # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') alarms = processing.get_alarms(session, user_id) return flask.make_response( flask.jsonify({'alarm_list': auxiliary.list_to_json(alarms)}), 200)
def get(self, args): """Get the list of highlights.""" year = args['year'] week = args['week'] with session_scope() as session: highlights = processing.get_response_highlights_week( session, year, week) return flask.make_response( flask.jsonify( {'highlight_list': auxiliary.list_to_json(highlights)}), 200)
def delete(self, args): """Delete a alarm.""" alarm_id = args['alarm_id'] with session_scope() as session: # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') processing.remove_alarm(session, alarm_id, user_id) return flask.make_response( flask.jsonify({ 'alarm_list': auxiliary.list_to_json( processing.get_alarms(session, user_id)) }), 200)
def delete(self, args): """Delete a reminder.""" reminder_id = args['reminder_id'] with session_scope() as session: # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') if db_calls.delete_reminder(session, reminder_id, user_id): return flask.make_response( flask.jsonify({ 'reminder_list': auxiliary.list_to_json( reminders.get_reminders(session, user_id)) }), 200) else: return flask.make_response('', 404)
def test_list_to_json(self) -> None: """ Test the function list_to_json. """ # The expected result expected_result = [{ 'number': 353, 'string': 'a string' }, { 'number': 123, 'string': 'other string' }] # Call the function auto_repr_test_1 = AutoReprTest('a string', 353) auto_repr_test_2 = AutoReprTest('other string', 123) actual_result = auxiliary.list_to_json( [auto_repr_test_1, auto_repr_test_2]) # Verify the result self.assertEqual(expected_result, actual_result)
def put(self, args): """Update an alarm.""" alarm_id = args['alarm_id'] show_season = args['show_season'] show_episode = args['show_episode'] with session_scope() as session: # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') if processing.update_alarm(session, alarm_id, show_season, show_episode, user_id): return flask.make_response( flask.jsonify({ 'alarm_list': auxiliary.list_to_json( processing.get_alarms(session, user_id)) }), 201) else: return flask.make_response('', 404)
def post(self, args): """Register a reminder.""" show_session_id = args['show_session_id'] anticipation_minutes = args['anticipation_minutes'] with session_scope() as session: # Get the user id from the token token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field(token.encode(), 'user') if reminders.register_reminder(session, show_session_id, anticipation_minutes, user_id) is not None: return flask.make_response( flask.jsonify({ 'reminder_list': auxiliary.list_to_json( reminders.get_reminders(session, user_id)) }), 201) else: return flask.make_response('Invalid reminder', 400)
def get(self, args): """Get search results for the search_text or the show_id, in the listings and streaming services.""" search_text = None show_id = None is_movie = None for k, v in args.items(): if v is None: continue if k == 'search_text': search_text = v.strip() if k == 'show_id': show_id = v if k == 'is_movie': is_movie = v if search_text is None and show_id is None: return flask.make_response('Invalid request', 400) with session_scope() as session: search_adult = False # Get the user settings of whether it should look in channels with adult content or not if 'HTTP_AUTHORIZATION' in flask.request.headers.environ: token = flask.request.headers.environ['HTTP_AUTHORIZATION'][7:] user_id = authentication.get_token_field( token.encode(), 'user') user = db_calls.get_user_id(session, user_id) search_adult = user.show_adult if user is not None else False # Check whether it is a request by id or by text if show_id is not None: if is_movie is None: return flask.make_response('Invalid request', 400) titles = processing.get_show_titles(session, show_id, is_movie) db_shows = processing.search_sessions_db_with_tmdb_id( session, show_id, is_movie) else: if len(search_text) < 2: return flask.make_response('Search Text Too Small', 400) titles = [search_text] db_shows = [] # If it is a search with id # - we only want exact title matches # - for those results that don't have a TMDB id complete_title = show_id is not None ignore_with_tmdb_id = show_id is not None # db_shows += processing.search_streaming_services_shows_db(session, titles, is_movie=is_movie, # complete_title=complete_title, # search_adult=search_adult, # ignore_with_tmdb_id=ignore_with_tmdb_id) db_shows += processing.search_sessions_db( session, titles, is_movie=is_movie, complete_title=complete_title, search_adult=search_adult, ignore_with_tmdb_id=ignore_with_tmdb_id) response_dict = {'show_list': auxiliary.list_to_json(db_shows)} show_dict = {} # If it is a search by id, add information on the premiere of the show if show_id is not None: show = db_calls.get_show_data_by_tmdb_id( session, show_id, is_movie) if show is not None: if show.premiere_date is not None: show_dict['premiere_date'] = show.premiere_date if show.season_premiere is not None: show_dict['season_premiere'] = show.season_premiere response_dict['show'] = show_dict return flask.make_response(flask.jsonify(response_dict), 200)