def makeQueryPOST(self, lines): urlList = [] for line in lines.split('\n'): # Skip empty lines if not len(line): continue try: net, sta, loc, cha, start, endt = line.split(' ') except: logging.error('Cannot parse line: %s' % line) continue # Empty location if loc == '--': loc = '' try: startParts = start.replace('-', ' ').replace('T', ' ') startParts = startParts.replace(':', ' ').replace('.', ' ') startParts = startParts.replace('Z', '').split() start = datetime.datetime(*map(int, startParts)) except: logging.error('Cannot convert "starttime" parameter (%s).' % start) continue try: endParts = endt.replace('-', ' ').replace('T', ' ') endParts = endParts.replace(':', ' ').replace('.', ' ') endParts = endParts.replace('Z', '').split() endt = datetime.datetime(*map(int, endParts)) except: logging.error('Cannot convert "endtime" parameter (%s).' % endt) continue try: fdsnws = self.routes.getRoute(net, sta, loc, cha, start, endt, 'dataselect') urlList.extend(applyFormat(fdsnws, 'get').splitlines()) except RoutingException: logging.warning('No route could be found for %s' % line) continue if not len(urlList): raise WIContentError('No routes have been found!') iterObj = ResultFile(urlList, self.acc.log if self.acc is not None else None) return iterObj
def makeQueryGET(self, parameters): # List all the accepted parameters allowedParams = ['net', 'network', 'sta', 'station', 'loc', 'location', 'cha', 'channel', 'start', 'starttime', 'end', 'endtime', 'user'] for param in parameters: if param not in allowedParams: #return 'Unknown parameter: %s' % param raise WIClientError('Unknown parameter: %s' % param) try: if 'network' in parameters: net = parameters['network'].value.upper() elif 'net' in parameters: net = parameters['net'].value.upper() else: net = '*' net = net.split(',') except: net = ['*'] try: if 'station' in parameters: sta = parameters['station'].value.upper() elif 'sta' in parameters: sta = parameters['sta'].value.upper() else: sta = '*' sta = sta.split(',') except: sta = ['*'] try: if 'location' in parameters: loc = parameters['location'].value.upper() elif 'loc' in parameters: loc = parameters['loc'].value.upper() else: loc = '*' loc = loc.split(',') except: loc = ['*'] try: if 'channel' in parameters: cha = parameters['channel'].value.upper() elif 'cha' in parameters: cha = parameters['cha'].value.upper() else: cha = '*' cha = cha.split(',') except: cha = ['*'] try: if 'starttime' in parameters: start = datetime.datetime.strptime( parameters['starttime'].value.upper(), '%Y-%m-%dT%H:%M:%S') elif 'start' in parameters: start = datetime.datetime.strptime( parameters['start'].value.upper(), '%Y-%m-%dT%H:%M:%S') else: raise Exception except: raise WIClientError('Error while converting starttime parameter.') try: if 'endtime' in parameters: endt = datetime.datetime.strptime( parameters['endtime'].value.upper(), '%Y-%m-%dT%H:%M:%S') elif 'end' in parameters: endt = datetime.datetime.strptime( parameters['end'].value.upper(), '%Y-%m-%dT%H:%M:%S') else: raise Exception except: raise WIClientError('Error while converting endtime parameter.') try: if 'user' in parameters: user = parameters['user'].value else: user = None except: raise Exception('Error while checking the user parameter') urlList = [] for (n, s, l, c) in lsNSLC(net, sta, loc, cha): try: fdsnws = self.routes.getRoute(n, s, l, c, start, endt, 'dataselect') urlList.extend(applyFormat(fdsnws, 'get').splitlines()) except RoutingException: pass if not len(urlList): raise WIContentError('No routes have been found!') iterObj = ResultFile(urlList, self.acc.log if self.acc is not None else None, user) return iterObj