I want to create a list of key-value pair with the output from /getService route.
I am able to filter the data that i wanted (Suburb and Services) from csv file vet_service_locations but want to have it as a key-value pair. Where keys are suburbs and services and values would be the relevant output.
I'm a beginner and tried different methods but nothing seems to work.
from bottle import html_quote, route, run, template, response, request
import petl as etl
from json import dumps
import csv
output = []
reading_file = etl.fromcsv('vet_service_locations.csv')
print(reading_file)
@route('/getServices')
def details():
postcode = request.query.postcode
print(postcode)
for row in reading_file:
if row[2] == postcode:
output.append(row[1])
output.append(row[4])
print(output)
run(host='localhost', port=3000, debug=True)
Vet_service_location.csv data image is in this link
Output I'm getting
[('Adelaide', 'Small_Animal'), ('Adelaide', 'Oncology'), ('Adelaide', 'Surgery'), ('Adelaide', 'Annual_Checkup'), ('Adelaide', 'Wildlife')]
Output I want
suburb, values
[('Adelaide', 'Small_Animal'),
('Adelaide', 'Oncology'),
('Adelaide', 'Surgery'),
('Adelaide', 'Annual_Checkup'),
('Adelaide', 'Wildlife')]
So, kinda like the table, the same structure in which the vet_service_locations.csv is.