def series(self, gnid=None, title=None, best=True, image=True, contributor=True, link=True): extended = [] if not gnid and not title: raise pyeQException('neither a gn_id nor a title specified') if image in TRUE: extended.append('IMAGE') if contributor in TRUE: extended.append('CONTRIBUTOR_IMAGE') if link in TRUE: extended.append('LINK') x = self.__query_xml() if gnid: cmd = 'SERIES_FETCH' else: cmd = 'SERIES_SEARCH' with x.QUERY(cmd=cmd): if not gnid and best: x.MODE('SINGLE_BEST') if not gnid: x.TEXT(title, TYPE='TITLE') else: x.GN_ID(gnid) if extended: with x.OPTION: x.PARAMETER('SELECT_EXTENDED') x.VALUE(','.join(extended)) return self.query_eyeq(x)['SERIES']
def tvgrid_search(self, title, channels = None, start = None, end = None, page=None, tvprogram_image=False, ipg_image=False): if isinstance(channels, str): channels = [channels] x = self.__query_xml() if page is not None and len(page) != 2: raise pyeQException('invalid range') with x.QUERY(CMD='TVGRID_SEARCH'): if channels is not None: with x.TVCHANNEL: for c in channels: x.GN_ID(str(c)) x.TEXT(title, TYPE='TVPROGRAM_TITLE') if start: try: start = start.astimezone(pytz.utc) except: start = self.tz.localize(start) start = start.astimezone(pytz.utc) x.DATE(start.strftime('%Y-%m-%dT%H:%M'), TYPE='START') if end: try: end = end.astimezone(pytz.utc) except: end = end.tz.localize(end) end = end.astimezone(pytz.utc) x.DATE(end.strftime('%Y-%m-%dT%H:%M'), TYPE='END') extended = [] if tvprogram_image in TRUE: extended.append('TVPROGRAM_IMAGE') if ipg_image in TRUE: extended.append('IPG_IMAGE') if extended: with x.OPTION: x.PARAMETER('SELECT_EXTENDED') x.VALUE(','.join(extended)) if page: with x.RANGE: x.START(page[0]) x.END(page[1]) response = self.query_eyeq(x)['TVGRID'] if isinstance(response['TVPROGRAM'], OrderedDict): response['TVPROGRAM'] = [response['TVPROGRAM']] programs = {v['GN_ID']: v for v in response['TVPROGRAM']} for airing in response['TVAIRING']: program = programs[airing['@TVPROGRAM_GN_ID']] if 'AIRINGS' not in program: program['AIRINGS'] = [] program['AIRINGS'].append({'CHANNEL':airing['@TVCHANNEL_GN_ID'], 'START':pytz.utc.localize(datetime.strptime(airing['@START'], '%Y-%m-%dT%H:%M')), 'END':pytz.utc.localize(datetime.strptime(airing['@END'], '%Y-%m-%dT%H:%M'))}) return programs.values(), (response['RANGE']['COUNT'], response['RANGE']['START'], response['RANGE']['END'])
def provider_channels(self, provider_id): if isinstance(provider_id, dict): provider_id = provider_id.get('GN_ID', None) if not provider_id: raise pyeQException('INVALID PROVIDER ID') x = self.__query_xml() with x.QUERY(CMD='TVCHANNEL_LOOKUP'): x.MODE('TVPROVIDER') x.GN_ID(provider_id) response = self.query_eyeq(x) return response['TVCHANNEL']
def query_eyeq(self, queryxml): try: response = urllib2.urlopen(self.URL, str(queryxml)) except urllib2.URLError: raise pyeQConnectionExcption('Could not connect to {0}'.format(self.URL)) response = xmltodict.parse(response) if response['RESPONSES']['RESPONSE']['@STATUS'] != 'OK': print str(queryxml), response status = response['RESPONSES']['RESPONSE']['@STATUS'] message = response['RESPONSES'].get('MESSAGE', '') if status == 'NO_MATCH': raise pyeQNotFoundException() raise pyeQException('query failed: {0} ({1})'.format(status, message)) return response['RESPONSES']['RESPONSE']
def query_eyeq(self, queryxml): try: response = urllib2.urlopen(self.URL, str(queryxml)) except urllib2.URLError: raise pyeQConnectionExcption('Could not connect to {0}'.format( self.URL)) response = xmltodict.parse(response) if response['RESPONSES']['RESPONSE']['@STATUS'] != 'OK': print str(queryxml), response status = response['RESPONSES']['RESPONSE']['@STATUS'] message = response['RESPONSES'].get('MESSAGE', '') if status == 'NO_MATCH': raise pyeQNotFoundException() raise pyeQException('query failed: {0} ({1})'.format( status, message)) return response['RESPONSES']['RESPONSE']
def grid_lookup(self, channels, start=None, end=None, mode=None, gnid=None, page=None, tvprogram_image=False, ipg_image=False): modes = {'CONTRIBUTOR', 'AV_WORK', 'SERIES', 'SEASON'} if isinstance(channels, str): channels = [channels] x = self.__query_xml() if mode is not None and mode.upper() not in modes: raise pyeQException('unsupported mode: {0}'.format(mode)) if mode is not None and gnid is None: raise pyeQException('{0} requires a gnid'.format(mode)) if page is not None and len(page) != 2: raise pyeQException('invalid range') with x.QUERY(CMD='TVGRID_LOOKUP'): with x.TVCHANNEL: for c in channels: x.GN_ID(str(c)) if start: try: start = start.astimezone(pytz.utc) except: start = self.tz.localize(start) start = start.astimezone(pytz.utc) x.DATE(start.strftime('%Y-%m-%dT%H:%M'), TYPE='START') if end: try: end = end.astimezone(pytz.utc) except: end = end.tz.localize(end) end = end.astimezone(pytz.utc) x.DATE(end.strftime('%Y-%m-%dT%H:%M'), TYPE='END') if mode is not None: x.MODE(mode.upper()) x.GN_ID(gnid) extended = [] if tvprogram_image in TRUE: extended.append('TVPROGRAM_IMAGE') if ipg_image in TRUE: extended.append('IPG_IMAGE') if extended: with x.OPTION: x.PARAMETER('SELECT_EXTENDED') x.VALUE(','.join(extended)) if page: with x.RANGE: x.START(str(page[0])) x.END(str(page[1])) response = self.query_eyeq(x)['TVGRID'] if isinstance(response['TVPROGRAM'], OrderedDict): response['TVPROGRAM'] = [response['TVPROGRAM']] programs = {v['GN_ID']: v for v in response['TVPROGRAM']} if isinstance(response['TVAIRING'], OrderedDict): response['TVAIRING']=[response['TVAIRING']] for airing in response['TVAIRING']: program = programs[airing['@TVPROGRAM_GN_ID']] if 'AIRINGS' not in program: program['AIRINGS'] = [] airing['@START'] = pytz.utc.localize(datetime.strptime(airing['@START'], '%Y-%m-%dT%H:%M')) airing['@END'] = pytz.utc.localize(datetime.strptime(airing['@END'], '%Y-%m-%dT%H:%M')) program['AIRINGS'].append({'CHANNEL':airing['@TVCHANNEL_GN_ID'], 'START':airing['@START'], 'END':airing['@END']}) return programs.values(), (response['RANGE']['COUNT'], response['RANGE']['START'], response['RANGE']['END'])
def grid_lookup(self, channels, start=None, end=None, mode=None, gnid=None, page=None, tvprogram_image=False, ipg_image=False): modes = {'CONTRIBUTOR', 'AV_WORK', 'SERIES', 'SEASON'} if isinstance(channels, str): channels = [channels] x = self.__query_xml() if mode is not None and mode.upper() not in modes: raise pyeQException('unsupported mode: {0}'.format(mode)) if mode is not None and gnid is None: raise pyeQException('{0} requires a gnid'.format(mode)) if page is not None and len(page) != 2: raise pyeQException('invalid range') with x.QUERY(CMD='TVGRID_LOOKUP'): with x.TVCHANNEL: for c in channels: x.GN_ID(str(c)) if start: try: start = start.astimezone(pytz.utc) except: start = self.tz.localize(start) start = start.astimezone(pytz.utc) x.DATE(start.strftime('%Y-%m-%dT%H:%M'), TYPE='START') if end: try: end = end.astimezone(pytz.utc) except: end = end.tz.localize(end) end = end.astimezone(pytz.utc) x.DATE(end.strftime('%Y-%m-%dT%H:%M'), TYPE='END') if mode is not None: x.MODE(mode.upper()) x.GN_ID(gnid) extended = [] if tvprogram_image in TRUE: extended.append('TVPROGRAM_IMAGE') if ipg_image in TRUE: extended.append('IPG_IMAGE') if extended: with x.OPTION: x.PARAMETER('SELECT_EXTENDED') x.VALUE(','.join(extended)) if page: with x.RANGE: x.START(str(page[0])) x.END(str(page[1])) response = self.query_eyeq(x)['TVGRID'] if isinstance(response['TVPROGRAM'], OrderedDict): response['TVPROGRAM'] = [response['TVPROGRAM']] programs = {v['GN_ID']: v for v in response['TVPROGRAM']} if isinstance(response['TVAIRING'], OrderedDict): response['TVAIRING'] = [response['TVAIRING']] for airing in response['TVAIRING']: program = programs[airing['@TVPROGRAM_GN_ID']] if 'AIRINGS' not in program: program['AIRINGS'] = [] airing['@START'] = pytz.utc.localize( datetime.strptime(airing['@START'], '%Y-%m-%dT%H:%M')) airing['@END'] = pytz.utc.localize( datetime.strptime(airing['@END'], '%Y-%m-%dT%H:%M')) program['AIRINGS'].append({ 'CHANNEL': airing['@TVCHANNEL_GN_ID'], 'START': airing['@START'], 'END': airing['@END'] }) return programs.values(), (response['RANGE']['COUNT'], response['RANGE']['START'], response['RANGE']['END'])
def tvgrid_search(self, title, channels=None, start=None, end=None, page=None, tvprogram_image=False, ipg_image=False): if isinstance(channels, str): channels = [channels] x = self.__query_xml() if page is not None and len(page) != 2: raise pyeQException('invalid range') with x.QUERY(CMD='TVGRID_SEARCH'): if channels is not None: with x.TVCHANNEL: for c in channels: x.GN_ID(str(c)) x.TEXT(title, TYPE='TVPROGRAM_TITLE') if start: try: start = start.astimezone(pytz.utc) except: start = self.tz.localize(start) start = start.astimezone(pytz.utc) x.DATE(start.strftime('%Y-%m-%dT%H:%M'), TYPE='START') if end: try: end = end.astimezone(pytz.utc) except: end = end.tz.localize(end) end = end.astimezone(pytz.utc) x.DATE(end.strftime('%Y-%m-%dT%H:%M'), TYPE='END') extended = [] if tvprogram_image in TRUE: extended.append('TVPROGRAM_IMAGE') if ipg_image in TRUE: extended.append('IPG_IMAGE') if extended: with x.OPTION: x.PARAMETER('SELECT_EXTENDED') x.VALUE(','.join(extended)) if page: with x.RANGE: x.START(page[0]) x.END(page[1]) response = self.query_eyeq(x)['TVGRID'] if isinstance(response['TVPROGRAM'], OrderedDict): response['TVPROGRAM'] = [response['TVPROGRAM']] programs = {v['GN_ID']: v for v in response['TVPROGRAM']} for airing in response['TVAIRING']: program = programs[airing['@TVPROGRAM_GN_ID']] if 'AIRINGS' not in program: program['AIRINGS'] = [] program['AIRINGS'].append({ 'CHANNEL': airing['@TVCHANNEL_GN_ID'], 'START': pytz.utc.localize( datetime.strptime(airing['@START'], '%Y-%m-%dT%H:%M')), 'END': pytz.utc.localize( datetime.strptime(airing['@END'], '%Y-%m-%dT%H:%M')) }) return programs.values(), (response['RANGE']['COUNT'], response['RANGE']['START'], response['RANGE']['END'])