def main_loop():
    # requested query
    inputServiceID = request.query.serviceid
    csv = pt.fromcsv('clinicservicelocations.csv')
    response.headers['Content-type'] = 'application/json'
    response.headers['Access-Control-Allow-Origin'] = '*'
    for i in csv:
        if inputServiceID == i[0]:
            # select the data according to the given requested query
            dataSelect = pt.select(
                csv, "{ServiceID} == '" + str(inputServiceID) + "'")
            # cutting out the required column names
            jsonData = pt.cut(dataSelect, 'Name', 'Service', 'Suburb', 'State',
                              'Email', 'Lat', 'Lon')
            # convert the dictionary data into json data
            jsonData = json.JSONEncoder().encode(list(pt.dicts(jsonData)))
            # return the json data
            return jsonData

        # this is requested link of getting all the distinct list of
        # clinics offering any service.
        if inputServiceID == "0":
            anyServices = pt.unique(csv, key='Name')
            jsonData = pt.cut(anyServices, 'Name', 'Service', 'Suburb',
                              'State', 'Email', 'Lat', 'Lon')
            jsonData = json.JSONEncoder().encode(list(pt.dicts(jsonData)))
            return jsonData
    else:
        jsonData = json.JSONEncoder().encode('Unable to find this id.')
        return jsonData
Exemplo n.º 2
0
def main_loop():
    # requested query
    Service = request.query.Service
    #Converting the Service value to String
    Service = str(Service)

    csv = petl.fromcsv(file)
    response.headers['Content-type'] = 'application/json'
    response.headers['Access-Control-Allow-Origin'] = '*'

    for i in csv:
        if Service == i[1]:
            # select the data according to the given requested query
            dataSelect = petl.select(csv, "{Service} == '" + Service + "'")
            # cutting out the required column names
            jsonData = petl.cut(dataSelect, 'ClinicID', 'Suburb', 'Lat', 'Lon')
            # convert the dictionary data into json data
            jsonData = json.JSONEncoder().encode(list(petl.dicts(jsonData)))
            # return the json data
            return jsonData

        # this is requested link of getting all the distinct list of clinics offering any service.
        if Service == "0":
            anyServices = petl.unique(csv, key='Name')
            jsonData = petl.cut(anyServices, 'ClinicID', 'Suburb', 'Lat',
                                'Lon')
            jsonData = json.JSONEncoder().encode(list(petl.dicts(jsonData)))
            return jsonData
    else:
        jsonData = json.JSONEncoder().encode('Please Enter a Service.')
        return jsonData
Exemplo n.º 3
0

# unique
table1 = (('foo', 'bar', 'baz'),
          ('A', 1, 2),
          ('B', '2', '3.4'),
          ('D', 'xyz', 9.0),
          ('B', u'3', u'7.8'),
          ('B', '2', 42),
          ('E', None, None),
          ('D', 4, 12.3),
          ('F', 7, 2.3))

from petl import unique, look
look(table1)
table2 = unique(table1, 'foo')
look(table2)


# isordered
table = (('foo', 'bar', 'baz'), 
         ('a', 1, True), 
         ('b', 3, True), 
         ('b', 2))

from petl import isordered, look
look(table)
isordered(table, key='foo')
isordered(table, key='foo', strict=True)
isordered(table, key='foo', reverse=True)
Exemplo n.º 4
0

# unique
table1 = (('foo', 'bar', 'baz'),
          ('A', 1, 2),
          ('B', '2', '3.4'),
          ('D', 'xyz', 9.0),
          ('B', u'3', u'7.8'),
          ('B', '2', 42),
          ('E', None, None),
          ('D', 4, 12.3),
          ('F', 7, 2.3))

from petl import unique, look
look(table1)
table2 = unique(table1, 'foo')
look(table2)


# isordered
table = (('foo', 'bar', 'baz'), 
         ('a', 1, True), 
         ('b', 3, True), 
         ('b', 2))

from petl import isordered, look
look(table)
isordered(table, key='foo')
isordered(table, key='foo', strict=True)
isordered(table, key='foo', reverse=True)
Exemplo n.º 5
0

# unique()
##########

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          ['A', 1, 2],
          ['B', '2', '3.4'],
          ['D', 'xyz', 9.0],
          ['B', u'3', u'7.8'],
          ['B', '2', 42],
          ['E', None, None],
          ['D', 4, 12.3],
          ['F', 7, 2.3]]
table2 = etl.unique(table1, 'foo')
table2


# conflicts()
#############

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          ['A', 1, 2.7],
          ['B', 2, None],
          ['D', 3, 9.4],
          ['B', None, 7.8],
          ['E', None],
          ['D', 3, 12.3],
          ['A', 2, None]]
Exemplo n.º 6
0
table1 = [['foo', 'bar', 'baz'], ['A', 1, 2.0], ['B', 2, 3.4], ['D', 6, 9.3],
          ['B', 3, 7.8], ['B', 2, 12.3], ['E', None, 1.3], ['D', 4, 14.5]]
table2 = etl.duplicates(table1, 'foo')
table2
# compound keys are supported
table3 = etl.duplicates(table1, key=['foo', 'bar'])
table3

# unique()
##########

import petl as etl
table1 = [['foo', 'bar', 'baz'], ['A', 1, 2], ['B', '2', '3.4'],
          ['D', 'xyz', 9.0], ['B', u'3', u'7.8'], ['B', '2', 42],
          ['E', None, None], ['D', 4, 12.3], ['F', 7, 2.3]]
table2 = etl.unique(table1, 'foo')
table2

# conflicts()
#############

import petl as etl
table1 = [['foo', 'bar', 'baz'], ['A', 1, 2.7], ['B', 2, None], ['D', 3, 9.4],
          ['B', None, 7.8], ['E', None], ['D', 3, 12.3], ['A', 2, None]]
table2 = etl.conflicts(table1, 'foo')
table2

# isunique()
############

import petl as etl