So I am new to coding and this is my first question so I apologise if the formatting is incorrect.
I am trying to figure out how to combine the (get_x_start) and the (get_x_end) functions {where x is the unique name given to the pair of functions} such that there is one function for each x that returns (field) and (end). I tried just using a list ie:
return (field,end)
But then when I tried I didn't know how to use those as indivual perameters within (main()) such that the function (fetch_data) could use both of the returned parameters from a single x function.
My code follows. If anything in it is unclear please let me know and I will try and clarify. Thanks.
def get_data (url):
response = url
return str(response.read())
def fetch_data (field,data,end):
sen = data[data.find(field)+len(field)+3:data.find(end)-3]
return sen
def get_name_start (data):
field = "Name"
return field
def get_name_end (data):
end = "ClosingTime"
return end
def get_open_start (data):
field = "OpeningTime"
return field
def get_open_end (data):
end = "Name"
return end
def get_close_start (data):
field = "ClosingTime"
return field
def get_close_end (data):
end = "CoLocated"
return end
def main ():
import urllib.request
data = get_data (urllib.request.urlopen('http://www.findfreewifi.co.za/publicjson/locationsnear?lat=-33.9568396&lng=18.45887&topX=1'))
print (fetch_data(get_name_start(data),data,get_name_end(data)))
print (fetch_data(get_open_start(data),data,get_open_end(data)))
print (fetch_data(get_close_start(data),data,get_close_end(data)))
main ()