Beispiel #1
0
def stash_data_to_disk(step):
    world.stashfile_pathname = os.path.abspath('scratch/bare.csv')
    #remove any preexisting/leftover stash instance with this file pathname
    if os.path.exists(world.stashfile_pathname):
        os.remove(world.stashfile_pathname)

    import pywqp_client
    client_instance = pywqp_client.RESTClient()
    client_instance.stash_response(world.response, world.stashfile_pathname)
    assert os.path.exists(world.stashfile_pathname)
Beispiel #2
0
def stash_message_to_disk(step):
    world.stashfile_pathname = os.path.abspath('scratch/bare.csv')
    #remove any preexisting/leftover stash instance with this EXPECTED file pathname
    expected_stashfile_pathname = world.stashfile_pathname + '.http'
    if os.path.exists(expected_stashfile_pathname):
        os.remove(expected_stashfile_pathname)

    import pywqp_client
    client_instance = pywqp_client.RESTClient()
    client_instance.stash_response(world.response, world.stashfile_pathname, raw_http=True)
    # did the method call do the expected thing?
    assert os.path.exists(expected_stashfile_pathname)
Beispiel #3
0
def make_call(step, verb):

    verb = verb.lower()

    # use pywqp_client
    setup_target_path()
    import pywqp_client
    client_instance = pywqp_client.RESTClient()

    # params
    params = {}
    params['countrycode'] = world.countrycode
    params['statecode'] = world.statecode
    params['countycode'] = world.countycode
    params['characteristicName'] = world.characteristic

    # default
    contenttype = 'text/csv'
    if hasattr(world, 'contenttype'):
        contenttype = world.contenttype
        
    world.response = client_instance.request_wqp_data(verb, world.wqpserver, world.resourcetype, params, contenttype)
Beispiel #4
0
    print('\n\n' + color_green + 'calling dataframe irow(' + str(row_to_display) + ')' + color_stop)
    print(dataframe.irow(row_to_display))
    print(color_green + 'done with irow(' + str(row_to_display) + ')' + color_stop)

# make pandas.DataFrame from the other data structure (rows-first)
if datadict2:
    dataframe = pandas.DataFrame(data=datadict2, columns=wqx_mappings.tabular_defs[table_type])
    print('\n\n' + color_yellow + 'calling dataframe irow(' + str(row_to_display) + ')' + color_stop)
    print(dataframe.irow(row_to_display))
    print(color_yellow + 'done with irow(' + str(row_to_display) + ')' + color_stop)

print('\n\n')

# use pywqp_client to fetch as dataframe
import pywqp_client
client_instance = pywqp_client.RESTClient()

# params
params = {}
params['countrycode'] = 'US'
params['statecode'] = 'US:55'
params['countycode'] = 'US:55:015'
params['characteristicName'] = 'pH'

response = client_instance.request_wqp_data('get', 'http://www.waterqualitydata.us', 'station', params, 'text/xml')

print('status code: ' + str(response.status_code))
for header in response.headers:
    print(header + ': ' + response.headers[header])

print
Beispiel #5
0
        than the date on which a particular measurement is actually obtained.)
    startDateHi
    sampleMedia
    characteristicType
    characteristicName
    pCode (An NWIS-only classification scheme for sampling procedures. Non-NWIS
        data sources will not provide any results to a query with a pCode
        parameter.)
    analyticalMethod (a classification of analytical protocols curated by NEMI
        (see [http://www.nemi.gov] for more information.) The value of this
        parameter is a published NEMI URI, _fully urlencoded_.)
'''

# paramfile is a listing of parameters, one per line, empty lines ignored.
# each parameter is of the form <name>=<value> (no angle brackets in real life.)
client = pywqp_client.RESTClient()
validator = pywqp_validator.WQPValidator()


def paramfile_args(filename):
    paramfile = open(filename, 'r')
    paramexprs = paramfile.readlines()
    paramfile.close()
    retval = {}
    for paramexpr in paramexprs:
        # process commandline arguments
        #if sys.argv['paramfile']:
        # do nothing so far
        if sys.argv['wqpResourceType']:
            for label in ('station', 'result', 'simplestation', 'bio'):
                print('label: ' + label + '; response type path: ' +