<s> from __future__ import unicode_literals <EOL> import json <EOL> import re <EOL> from datetime import datetime <EOL> from pytvmaze import endpoints <EOL> from pytvmaze . exceptions import * <EOL> try : <EOL> from urllib . request import urlopen <EOL> from urllib . parse import quote as url_quote , unquote as url_unquote <EOL> from urllib . error import URLError , HTTPError <EOL> except ImportError : <EOL> from urllib2 import urlopen , URLError , HTTPError <EOL> from urllib import quote as url_quote , unquote as url_unquote <EOL> def _valid_encoding ( text ) : <EOL> if not text : <EOL> return <EOL> if sys . version_info > ( <NUM_LIT:3> , ) : <EOL> return text <EOL> else : <EOL> return unicode ( text ) . encode ( '<STR_LIT:utf-8>' ) <EOL> class Show ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . status = data . get ( '<STR_LIT:status>' ) <EOL> self . rating = data . get ( '<STR_LIT>' ) <EOL> self . genres = data . get ( '<STR_LIT>' ) <EOL> self . weight = data . get ( '<STR_LIT>' ) <EOL> self . updated = data . get ( '<STR_LIT>' ) <EOL> self . name = data . get ( '<STR_LIT:name>' ) <EOL> self . language = data . get ( '<STR_LIT>' ) <EOL> self . schedule = data . get ( '<STR_LIT>' ) <EOL> self . url = data . get ( '<STR_LIT:url>' ) <EOL> self . image = data . get ( '<STR_LIT:image>' ) <EOL> self . externals = data . get ( '<STR_LIT>' ) <EOL> self . premiered = data . get ( '<STR_LIT>' ) <EOL> self . summary = _remove_tags ( data . get ( '<STR_LIT>' ) ) <EOL> self . links = data . get ( '<STR_LIT>' ) <EOL> self . web_channel = data . get ( '<STR_LIT>' ) <EOL> self . runtime = data . get ( '<STR_LIT>' ) <EOL> self . type = data . get ( '<STR_LIT:type>' ) <EOL> self . id = data . get ( '<STR_LIT:id>' ) <EOL> self . maze_id = self . id <EOL> self . network = data . get ( '<STR_LIT>' ) <EOL> self . episodes = list ( ) <EOL> self . seasons = dict ( ) <EOL> self . cast = None <EOL> self . __nextepisode = None <EOL> self . __previousepisode = None <EOL> self . populate ( data ) <EOL> def __repr__ ( self ) : <EOL> if self . premiered : <EOL> year = str ( self . premiered [ : <NUM_LIT:4> ] ) <EOL> else : <EOL> year = None <EOL> if self . web_channel : <EOL> platform = '<STR_LIT>' <EOL> network = self . web_channel . get ( '<STR_LIT:name>' ) <EOL> elif self . network : <EOL> platform = '<STR_LIT>' <EOL> network = self . network . get ( '<STR_LIT:name>' ) <EOL> else : <EOL> platform = '<STR_LIT>' <EOL> network = '<STR_LIT>' <EOL> return _valid_encoding ( '<STR_LIT>' . format ( <EOL> id = self . maze_id , <EOL> name = self . name , <EOL> year = year , <EOL> platform = platform , <EOL> network = network ) <EOL> ) <EOL> def __str__ ( self ) : <EOL> return _valid_encoding ( self . name ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> def __iter__ ( self ) : <EOL> return iter ( self . seasons . values ( ) ) <EOL> def __bool__ ( self ) : <EOL> return bool ( self . id ) <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . id ) <EOL> def __len__ ( self ) : <EOL> return len ( self . seasons ) <EOL> def __getitem__ ( self , item ) : <EOL> try : <EOL> return self . seasons [ item ] <EOL> except KeyError : <EOL> raise SeasonNotFound ( '<STR_LIT>' . format ( item , self . name ) ) <EOL> @ property <EOL> def next_episode ( self ) : <EOL> if self . __nextepisode is None and '<STR_LIT>' in self . links and '<STR_LIT>' in self . links [ '<STR_LIT>' ] : <EOL> episode_id = self . links [ '<STR_LIT>' ] [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> if episode_id . isdigit ( ) : <EOL> self . __nextepisode = episode_by_id ( episode_id ) <EOL> return self . __nextepisode <EOL> @ property <EOL> def previous_episode ( self ) : <EOL> if self . __previousepisode is None and '<STR_LIT>' in self . links and '<STR_LIT>' in self . links [ '<STR_LIT>' ] : <EOL> episode_id = self . links [ '<STR_LIT>' ] [ '<STR_LIT>' ] . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> if episode_id . isdigit ( ) : <EOL> self . __previousepisode = episode_by_id ( episode_id ) <EOL> return self . __previousepisode <EOL> def populate ( self , data ) : <EOL> embedded = data . get ( '<STR_LIT>' ) <EOL> if embedded : <EOL> if embedded . get ( '<STR_LIT>' ) : <EOL> seasons = show_seasons ( self . maze_id ) <EOL> for episode in embedded . get ( '<STR_LIT>' ) : <EOL> self . episodes . append ( Episode ( episode ) ) <EOL> for episode in self . episodes : <EOL> season_num = int ( episode . season_number ) <EOL> if season_num not in self . seasons : <EOL> self . seasons [ season_num ] = seasons [ season_num ] <EOL> self . seasons [ season_num ] . show = self <EOL> self . seasons [ season_num ] . episodes [ episode . episode_number ] = episode <EOL> if embedded . get ( '<STR_LIT>' ) : <EOL> self . cast = Cast ( embedded . get ( '<STR_LIT>' ) ) <EOL> class Season ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . show = None <EOL> self . episodes = dict ( ) <EOL> self . id = data . get ( '<STR_LIT:id>' ) <EOL> self . url = data . get ( '<STR_LIT:url>' ) <EOL> self . season_number = data . get ( '<STR_LIT>' ) <EOL> self . name = data . get ( '<STR_LIT:name>' ) <EOL> self . episode_order = data . get ( '<STR_LIT>' ) <EOL> self . premier_date = data . get ( '<STR_LIT>' ) <EOL> self . end_date = data . get ( '<STR_LIT>' ) <EOL> self . network = data . get ( '<STR_LIT>' ) <EOL> self . web_channel = data . get ( '<STR_LIT>' ) <EOL> self . image = data . get ( '<STR_LIT:image>' ) <EOL> self . summary = data . get ( '<STR_LIT>' ) <EOL> self . links = data . get ( '<STR_LIT>' ) <EOL> def __repr__ ( self ) : <EOL> return _valid_encoding ( '<STR_LIT>' . format ( <EOL> id = self . id , <EOL> number = str ( self . season_number ) . zfill ( <NUM_LIT:2> ) <EOL> ) ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . episodes . values ( ) ) <EOL> def __len__ ( self ) : <EOL> return len ( self . episodes ) <EOL> def __getitem__ ( self , item ) : <EOL> try : <EOL> return self . episodes [ item ] <EOL> except KeyError : <EOL> raise EpisodeNotFound ( <EOL> '<STR_LIT>' . format ( item , self . season_number , <EOL> self . show ) ) <EOL> def __bool__ ( self ) : <EOL> return bool ( self . id ) <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . id ) <EOL> class Episode ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . title = data . get ( '<STR_LIT:name>' ) <EOL> self . airdate = data . get ( '<STR_LIT>' ) <EOL> self . url = data . get ( '<STR_LIT:url>' ) <EOL> self . season_number = data . get ( '<STR_LIT>' ) <EOL> self . episode_number = data . get ( '<STR_LIT>' ) <EOL> self . image = data . get ( '<STR_LIT:image>' ) <EOL> self . airstamp = data . get ( '<STR_LIT>' ) <EOL> self . airtime = data . get ( '<STR_LIT>' ) <EOL> self . runtime = data . get ( '<STR_LIT>' ) <EOL> self . summary = _remove_tags ( data . get ( '<STR_LIT>' ) ) <EOL> self . maze_id = data . get ( '<STR_LIT:id>' ) <EOL> if data . get ( '<STR_LIT>' ) : <EOL> self . show = Show ( data . get ( '<STR_LIT>' ) ) <EOL> if data . get ( '<STR_LIT>' ) : <EOL> if data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) : <EOL> self . show = Show ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> season = str ( self . season_number ) . zfill ( <NUM_LIT:2> ) , <EOL> number = str ( self . episode_number ) . zfill ( <NUM_LIT:2> ) <EOL> ) <EOL> def __str__ ( self ) : <EOL> season = '<STR_LIT:S>' + str ( self . season_number ) . zfill ( <NUM_LIT:2> ) <EOL> episode = '<STR_LIT:E>' + str ( self . episode_number ) . zfill ( <NUM_LIT:2> ) <EOL> return _valid_encoding ( season + episode + '<STR_LIT:U+0020>' + self . title ) <EOL> class Person ( object ) : <EOL> def __init__ ( self , data ) : <EOL> if data . get ( '<STR_LIT>' ) : <EOL> data = data [ '<STR_LIT>' ] <EOL> self . links = data . get ( '<STR_LIT>' ) <EOL> self . id = data . get ( '<STR_LIT:id>' ) <EOL> self . image = data . get ( '<STR_LIT:image>' ) <EOL> self . name = data . get ( '<STR_LIT:name>' ) <EOL> self . score = data . get ( '<STR_LIT>' ) <EOL> self . url = data . get ( '<STR_LIT:url>' ) <EOL> self . character = None <EOL> self . castcredits = None <EOL> self . crewcredits = None <EOL> self . populate ( data ) <EOL> def populate ( self , data ) : <EOL> if data . get ( '<STR_LIT>' ) : <EOL> if data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) : <EOL> self . castcredits = [ CastCredit ( credit ) <EOL> for credit in data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] <EOL> elif data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) : <EOL> self . crewcredits = [ CrewCredit ( credit ) <EOL> for credit in data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ] <EOL> def __repr__ ( self ) : <EOL> return _valid_encoding ( '<STR_LIT>' . format ( <EOL> name = self . name , <EOL> id = self . id <EOL> ) ) <EOL> def __str__ ( self ) : <EOL> return _valid_encoding ( self . name ) <EOL> class Character ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . id = data . get ( '<STR_LIT:id>' ) <EOL> self . url = data . get ( '<STR_LIT:url>' ) <EOL> self . name = data . get ( '<STR_LIT:name>' ) <EOL> self . image = data . get ( '<STR_LIT:image>' ) <EOL> self . links = data . get ( '<STR_LIT>' ) <EOL> self . person = None <EOL> def __repr__ ( self ) : <EOL> return _valid_encoding ( '<STR_LIT>' . format ( <EOL> name = self . name , <EOL> id = self . id <EOL> ) ) <EOL> def __str__ ( self ) : <EOL> return _valid_encoding ( self . name ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class Cast ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . people = [ ] <EOL> self . characters = [ ] <EOL> self . populate ( data ) <EOL> def populate ( self , data ) : <EOL> for cast_member in data : <EOL> self . people . append ( Person ( cast_member [ '<STR_LIT>' ] ) ) <EOL> self . characters . append ( Character ( cast_member [ '<STR_LIT>' ] ) ) <EOL> self . people [ - <NUM_LIT:1> ] . character = self . characters [ - <NUM_LIT:1> ] <EOL> self . characters [ - <NUM_LIT:1> ] . person = self . people [ - <NUM_LIT:1> ] <EOL> class CastCredit ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . links = data . get ( '<STR_LIT>' ) <EOL> self . character = None <EOL> self . show = None <EOL> self . populate ( data ) <EOL> def populate ( self , data ) : <EOL> if data . get ( '<STR_LIT>' ) : <EOL> if data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) : <EOL> self . character = Character ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> elif data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) : <EOL> self . show = Show ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> class CrewCredit ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . links = data . get ( '<STR_LIT>' ) <EOL> self . type = data . get ( '<STR_LIT:type>' ) <EOL> self . show = None <EOL> self . populate ( data ) <EOL> def populate ( self , data ) : <EOL> if data . get ( '<STR_LIT>' ) : <EOL> if data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) : <EOL> self . show = Show ( data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> class Updates ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . updates = dict ( ) <EOL> self . populate ( data ) <EOL> def populate ( self , data ) : <EOL> for maze_id , time in data . items ( ) : <EOL> self . updates [ int ( maze_id ) ] = Update ( maze_id , time ) <EOL> def __getitem__ ( self , item ) : <EOL> try : <EOL> return self . updates [ item ] <EOL> except KeyError : <EOL> raise UpdateNotFound ( '<STR_LIT>' . format ( item ) ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . updates . values ( ) ) <EOL> class Update ( object ) : <EOL> def __init__ ( self , maze_id , time ) : <EOL> self . maze_id = int ( maze_id ) <EOL> self . seconds_since_epoch = time <EOL> self . timestamp = datetime . fromtimestamp ( time ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> maze_id = self . maze_id , <EOL> time = self . seconds_since_epoch <EOL> ) <EOL> class AKA ( object ) : <EOL> def __init__ ( self , data ) : <EOL> self . country = data . get ( '<STR_LIT>' ) <EOL> self . name = data . get ( '<STR_LIT:name>' ) <EOL> def _remove_tags ( text ) : <EOL> return re . sub ( r'<STR_LIT>' , '<STR_LIT>' , text ) <EOL> def _query_endpoint ( url ) : <EOL> try : <EOL> data = urlopen ( url ) . read ( ) <EOL> except HTTPError as e : <EOL> if e . code in [ <NUM_LIT> , <NUM_LIT> ] : <EOL> return None <EOL> elif e . code == <NUM_LIT> : <EOL> raise BadRequest ( e . reason + '<STR_LIT:U+0020>' + str ( e . code ) + '<STR_LIT:U+0020>' + e . url ) <EOL> except URLError as e : <EOL> raise ConnectionError ( repr ( e ) ) <EOL> try : <EOL> results = json . loads ( data ) <EOL> except : <EOL> results = json . loads ( data . decode ( '<STR_LIT:utf8>' ) ) <EOL> if results : <EOL> return results <EOL> else : <EOL> return None <EOL> def get_show ( maze_id = None , tvdb_id = None , tvrage_id = None , imdb_id = None , show_name = None , <EOL> show_year = None , show_network = None , show_language = None , <EOL> show_country = None , show_web_channel = None , embed = None ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> if not ( maze_id or tvdb_id or tvrage_id or imdb_id or show_name ) : <EOL> raise MissingParameters ( <EOL> '<STR_LIT>' ) <EOL> if maze_id : <EOL> try : <EOL> return show_main_info ( maze_id , embed = embed ) <EOL> except IDNotFound as e : <EOL> errors . append ( e . value ) <EOL> if tvdb_id : <EOL> try : <EOL> return show_main_info ( lookup_tvdb ( tvdb_id ) . id , embed = embed ) <EOL> except IDNotFound as e : <EOL> errors . append ( e . value ) <EOL> if tvrage_id : <EOL> try : <EOL> return show_main_info ( lookup_tvrage ( tvrage_id ) . id , embed = embed ) <EOL> except IDNotFound as e : <EOL> errors . append ( e . value ) <EOL> if imdb_id : <EOL> try : <EOL> return show_main_info ( lookup_imdb ( imdb_id ) . id , embed = embed ) <EOL> except IDNotFound as e : <EOL> errors . append ( e . value ) <EOL> if show_name : <EOL> try : <EOL> show = _get_show_by_search ( show_name , show_year , show_network , show_language , show_country , <EOL> show_web_channel , embed = embed ) <EOL> return show <EOL> except ShowNotFound as e : <EOL> errors . append ( e . value ) <EOL> raise ShowNotFound ( '<STR_LIT>' . join ( errors ) ) <EOL> def _get_show_with_qualifiers ( show_name , qualifiers ) : <EOL> shows = get_show_list ( show_name ) <EOL> best_match = - <NUM_LIT:1> <EOL> show_match = None <EOL> for show in shows : <EOL> if show . premiered : <EOL> premiered = show . premiered [ : - <NUM_LIT:6> ] . lower ( ) <EOL> else : <EOL> premiered = None <EOL> if show . network and show . network . get ( '<STR_LIT:name>' ) : <EOL> network = show . network [ '<STR_LIT:name>' ] . lower ( ) <EOL> else : <EOL> network = None <EOL> if show . web_channel and show . web_channel . get ( '<STR_LIT:name>' ) : <EOL> web_channel = show . web_channel [ '<STR_LIT:name>' ] . lower ( ) <EOL> else : <EOL> web_channel = None <EOL> if show . network and show . network . get ( '<STR_LIT>' ) and show . network [ '<STR_LIT>' ] . get ( '<STR_LIT:code>' ) : <EOL> country = show . network [ '<STR_LIT>' ] [ '<STR_LIT:code>' ] . lower ( ) <EOL> else : <EOL> if show . web_channel and show . web_channel . get ( '<STR_LIT>' ) and show . web_channel [ '<STR_LIT>' ] . get ( '<STR_LIT:code>' ) : <EOL> country = show . web_channel [ '<STR_LIT>' ] [ '<STR_LIT:code>' ] . lower ( ) <EOL> else : <EOL> country = None <EOL> if show . language : <EOL> language = show . language . lower ( ) <EOL> else : <EOL> language = None <EOL> attributes = [ premiered , country , network , language , web_channel ] <EOL> show_score = len ( set ( qualifiers ) & set ( attributes ) ) <EOL> if show_score > best_match : <EOL> best_match = show_score <EOL> show_match = show <EOL> return show_match <EOL> def _get_show_by_search ( show_name , show_year , show_network , show_language , show_country , show_web_channel , embed ) : <EOL> if show_year : <EOL> show_year = str ( show_year ) <EOL> qualifiers = list ( filter ( None , [ show_year , show_network , show_language , show_country , show_web_channel ] ) ) <EOL> if qualifiers : <EOL> qualifiers = [ q . lower ( ) for q in qualifiers if q ] <EOL> show = _get_show_with_qualifiers ( show_name , qualifiers ) <EOL> else : <EOL> return show_single_search ( show = show_name , embed = embed ) <EOL> if embed : <EOL> return show_main_info ( maze_id = show . id , embed = embed ) <EOL> else : <EOL> return show <EOL> def _url_quote ( show ) : <EOL> return url_quote ( show . encode ( '<STR_LIT>' ) ) <EOL> def get_show_list ( show_name ) : <EOL> """<STR_LIT>""" <EOL> shows = show_search ( show_name ) <EOL> return shows <EOL> def get_people ( name ) : <EOL> """<STR_LIT>""" <EOL> people = people_search ( name ) <EOL> if people : <EOL> return people <EOL> def show_search ( show ) : <EOL> _show = _url_quote ( show ) <EOL> url = endpoints . show_search . format ( _show ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> shows = [ ] <EOL> for result in q : <EOL> show = Show ( result [ '<STR_LIT>' ] ) <EOL> show . score = result [ '<STR_LIT>' ] <EOL> shows . append ( show ) <EOL> return shows <EOL> else : <EOL> raise ShowNotFound ( '<STR_LIT>' . format ( show ) ) <EOL> def show_single_search ( show , embed = None ) : <EOL> _show = _url_quote ( show ) <EOL> if embed : <EOL> url = endpoints . show_single_search . format ( _show ) + '<STR_LIT>' + embed <EOL> else : <EOL> url = endpoints . show_single_search . format ( _show ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Show ( q ) <EOL> else : <EOL> raise ShowNotFound ( '<STR_LIT>' . format ( show ) ) <EOL> def lookup_tvrage ( tvrage_id ) : <EOL> url = endpoints . lookup_tvrage . format ( tvrage_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Show ( q ) <EOL> else : <EOL> raise IDNotFound ( '<STR_LIT>' . format ( tvrage_id ) ) <EOL> def lookup_tvdb ( tvdb_id ) : <EOL> url = endpoints . lookup_tvdb . format ( tvdb_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Show ( q ) <EOL> else : <EOL> raise IDNotFound ( '<STR_LIT>' . format ( tvdb_id ) ) <EOL> def lookup_imdb ( imdb_id ) : <EOL> url = endpoints . lookup_imdb . format ( imdb_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Show ( q ) <EOL> else : <EOL> raise IDNotFound ( '<STR_LIT>' . format ( imdb_id ) ) <EOL> def get_schedule ( country = '<STR_LIT>' , date = str ( datetime . today ( ) . date ( ) ) ) : <EOL> url = endpoints . get_schedule . format ( country , date ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ Episode ( episode ) for episode in q ] <EOL> else : <EOL> raise ScheduleNotFound ( '<STR_LIT>' . format ( country , date ) ) <EOL> def get_full_schedule ( ) : <EOL> url = endpoints . get_full_schedule <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ Episode ( episode ) for episode in q ] <EOL> else : <EOL> raise GeneralError ( '<STR_LIT>' ) <EOL> def show_main_info ( maze_id , embed = None ) : <EOL> if embed : <EOL> url = endpoints . show_main_info . format ( maze_id ) + '<STR_LIT>' + embed <EOL> else : <EOL> url = endpoints . show_main_info . format ( maze_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Show ( q ) <EOL> else : <EOL> raise IDNotFound ( '<STR_LIT>' . format ( maze_id ) ) <EOL> def episode_list ( maze_id , specials = None ) : <EOL> if specials : <EOL> url = endpoints . episode_list . format ( maze_id ) + '<STR_LIT>' <EOL> else : <EOL> url = endpoints . episode_list . format ( maze_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ Episode ( episode ) for episode in q ] <EOL> else : <EOL> raise IDNotFound ( '<STR_LIT>' . format ( maze_id ) ) <EOL> def episode_by_number ( maze_id , season_number , episode_number ) : <EOL> url = endpoints . episode_by_number . format ( maze_id , <EOL> season_number , <EOL> episode_number ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Episode ( q ) <EOL> else : <EOL> raise EpisodeNotFound ( <EOL> '<STR_LIT>' . format ( season_number , episode_number , <EOL> maze_id ) ) <EOL> def episodes_by_date ( maze_id , airdate ) : <EOL> try : <EOL> datetime . strptime ( airdate , '<STR_LIT>' ) <EOL> except ValueError : <EOL> raise IllegalAirDate ( '<STR_LIT>' ) <EOL> url = endpoints . episodes_by_date . format ( maze_id , airdate ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ Episode ( episode ) for episode in q ] <EOL> else : <EOL> raise NoEpisodesForAirdate ( <EOL> '<STR_LIT>' . format ( airdate , maze_id ) ) <EOL> def show_cast ( maze_id ) : <EOL> url = endpoints . show_cast . format ( maze_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Cast ( q ) <EOL> else : <EOL> raise CastNotFound ( '<STR_LIT>' . format ( maze_id ) ) <EOL> def show_index ( page = <NUM_LIT:1> ) : <EOL> url = endpoints . show_index . format ( page ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ Show ( show ) for show in q ] <EOL> else : <EOL> raise ShowIndexError ( '<STR_LIT>' ) <EOL> def people_search ( person ) : <EOL> person = _url_quote ( person ) <EOL> url = endpoints . people_search . format ( person ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ Person ( person ) for person in q ] <EOL> else : <EOL> raise PersonNotFound ( '<STR_LIT>' . format ( person ) ) <EOL> def person_main_info ( person_id , embed = None ) : <EOL> if embed : <EOL> url = endpoints . person_main_info . format ( person_id ) + '<STR_LIT>' + embed <EOL> else : <EOL> url = endpoints . person_main_info . format ( person_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Person ( q ) <EOL> else : <EOL> raise PersonNotFound ( '<STR_LIT>' . format ( person_id ) ) <EOL> def person_cast_credits ( person_id , embed = None ) : <EOL> if embed : <EOL> url = endpoints . person_cast_credits . format ( person_id ) + '<STR_LIT>' + embed <EOL> else : <EOL> url = endpoints . person_cast_credits . format ( person_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ CastCredit ( credit ) for credit in q ] <EOL> else : <EOL> raise CreditsNotFound ( '<STR_LIT>' . format ( person_id ) ) <EOL> def person_crew_credits ( person_id , embed = None ) : <EOL> if embed : <EOL> url = endpoints . person_crew_credits . format ( person_id ) + '<STR_LIT>' + embed <EOL> else : <EOL> url = endpoints . person_crew_credits . format ( person_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ CrewCredit ( credit ) for credit in q ] <EOL> else : <EOL> raise CreditsNotFound ( '<STR_LIT>' . format ( person_id ) ) <EOL> def show_updates ( ) : <EOL> url = endpoints . show_updates <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Updates ( q ) <EOL> else : <EOL> raise ShowIndexError ( '<STR_LIT>' ) <EOL> def show_akas ( maze_id ) : <EOL> url = endpoints . show_akas . format ( maze_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return [ AKA ( aka ) for aka in q ] <EOL> else : <EOL> raise AKASNotFound ( '<STR_LIT>' . format ( maze_id ) ) <EOL> def show_seasons ( maze_id ) : <EOL> url = endpoints . show_seasons . format ( maze_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> season_dict = dict ( ) <EOL> for season in q : <EOL> season_dict [ season [ '<STR_LIT>' ] ] = Season ( season ) <EOL> return season_dict <EOL> else : <EOL> raise SeasonNotFound ( '<STR_LIT>' . format ( maze_id ) ) <EOL> def season_by_id ( season_id ) : <EOL> url = endpoints . season_by_id . format ( season_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Season ( q ) <EOL> else : <EOL> raise SeasonNotFound ( '<STR_LIT>' . format ( season_id ) ) <EOL> def episode_by_id ( episode_id ) : <EOL> url = endpoints . episode_by_id . format ( episode_id ) <EOL> q = _query_endpoint ( url ) <EOL> if q : <EOL> return Episode ( q ) <EOL> else : <EOL> raise EpisodeNotFound ( '<STR_LIT>' . format ( episode_id ) ) </s>
