def _download(self, data): """ Download all data, even if paginated. """ page = 1 results = [] while True: data['page'] = page url = self.url + urllib.parse.urlencode(data) log.debug(f'Opening {url}') fd = urllib.request.urlopen(url) try: result = codecs.decode(fd.read(), encoding='utf-8', errors='replace') result = json.loads(result) except Exception as e: raise IOError( "Failed to load return from the HEKClient.") from e finally: fd.close() results.extend(result['result']) if not result['overmax']: if len(results) > 0: return astropy.table.Table(dict_keys_same(results)) else: return astropy.table.Table() page += 1
def _download(self, data): """ Download all data, even if paginated. """ page = 1 results = [] while True: data['page'] = page fd = urllib.request.urlopen(self.url + urllib.parse.urlencode(data)) try: result = json.load(fd) except Exception as e: raise IOError( "Failed to load return from the HEKClient.") from e finally: fd.close() results.extend(result['result']) if not result['overmax']: if len(results) > 0: return HEKTable(dict_keys_same(results)) else: return HEKTable() page += 1
def _download(self, data): """ Download all data, even if paginated. """ page = 1 results = [] new_data = data.copy() # Override the default name of the operatorX, where X is a number. for key in data.keys(): if "operator" in key: new_data[f"op{key.split('operator')[-1]}"] = new_data.pop(key) while True: new_data['page'] = page url = self.url + urllib.parse.urlencode(new_data) log.debug(f'Opening {url}') fd = urllib.request.urlopen(url) try: result = codecs.decode(fd.read(), encoding='utf-8', errors='replace') result = json.loads(result) except Exception as e: raise IOError( "Failed to load return from the HEKClient.") from e finally: fd.close() results.extend(result['result']) if not result['overmax']: if len(results) > 0: return astropy.table.Table(dict_keys_same(results)) else: return astropy.table.Table() page += 1
def _download(self, data): """ Download all data, even if paginated. """ page = 1 results = [] reader = codecs.getreader("utf-8") while True: data['page'] = page fd = urllib.request.urlopen( self.url, urllib.parse.urlencode(data).encode('utf-8')) try: result = json.load(reader(fd)) finally: fd.close() results.extend(result['result']) if not result['overmax']: if len(results) > 0: return HEKTable(dict_keys_same(results)) else: return HEKTable() page += 1