def POST(self): import web print('post started') json_data = web.data() JSONServerClass.setPerson(json_data) # need to convert to List Object to Json String else Angular cannot process it personInJsonString = json.dumps(JSONServerClass.getPerson()) print('return json-->' , personInJsonString ) return personInJsonString
def searchName(name): print('searching for-->', name) for person in JSONServerClass.getPerson( ): # For Loop, 1 record loop 1 time, 2 records loop 2 times personLocal = Person() # new object creation personLocal.__dict__ = person # convert to json print('personLocal name-->', personLocal.name) # printing person name isMatch = personLocal.name == name # is input == to the json object? {'name': 'Kiruban', 'address': 'Selangor'} print('isMatch ? -->', isMatch) if isMatch: # isMatch is true? return True return False
def searchPostCode(postcode): print('Input postcode-->', postcode) for person in JSONServerClass.getPerson(): personLocal = Person() # new object creation personLocal.__dict__ = person # convert to json print('\n') print('--Loop-- personLocal postcode -->', personLocal.postcode) isMatching = personLocal.postcode == postcode print('isMatching --->', isMatching) if (isMatching): return True return False
def searchAddress(address): print('Input address-->', address) for person in JSONServerClass.getPerson(): personLocal = Person() # new object creation personLocal.__dict__ = person # convert to json print('\n') print('personLocal address -->', personLocal.address) #isBlackPrint = personLocal.name == 'BLACKPINK' #print ('isBlackPrint --->' , isBlackPrint) isMatching = personLocal.address == address print('isMatching --->', isMatching) if (isMatching): return True return False
def searchAddress(address): # Looping of the json list in the memory. # In this example, it has only 1 loop cause got 1 data only for person in JSONServerClass.getPerson(): # Convert into Json Object First from Json String personLocal = Car() personLocal.__dict__ = person # Compare the input "Selangor" with data inside memory isMatch = personLocal.model == address if isMatch: return True return False
def GET(self): # need to convert to List Object to Json String else Angular cannot process it personInJsonString = json.dumps(JSONServerClass.getPerson()) print('return json-->' , personInJsonString ) return personInJsonString
# This is to simulate the "POST" API from PostMan from cls.server.json_server_method import JSONServerClass JSONServerClass.setPerson('{"name":"Kiruban","address":"Selangor"}') # This is to simulate the "GET" API from PostMan print('value inside memory------------->', JSONServerClass.getPerson())
personLocal = Person() # new object creation personLocal.__dict__ = person # convert to json print('\n') print('--Loop-- personLocal postcode -->', personLocal.postcode) isMatching = personLocal.postcode == postcode print('isMatching --->', isMatching) if (isMatching): return True return False # Load the Memory for string value below # This is to skip the Server Process JSONServerClass.setPerson( '{"name":"Kiruban","address":"Selangor","postcode":"10000" }') JSONServerClass.setPerson( '{"name":"jisoo","address":"seoul","postcode":"250"}') JSONServerClass.setPerson( '{"name":"jennie","address":"karachi ","postcode":"1999"}') print('JSONServerClass--->', JSONServerClass) print('\n') # address = 'mumbai' postcode = '1999' print(postcode, ' postcode exist? --->', JSONServerSearch.searchPostCode(postcode))
# Looping of the json list in the memory. # In this example, it has only 1 loop cause got 1 data only for person in JSONServerClass.getPerson(): # Convert into Json Object First from Json String personLocal = Car() personLocal.__dict__ = person # Compare the input "Selangor" with data inside memory isMatch = personLocal.model == address if isMatch: return True return False # Load the Memory for string value below # This is to skip the Server Process JSONServerClass.setPerson('{"name":"Kiruban","address":"Selangor"}') print('\n') address = 'Selangor1' print(address, ' value Matching? --->', JSONServerSearchTest.searchAddress(address)) print('\n') address = 'Selangor' print(address, ' value Matching? --->', JSONServerSearchTest.searchAddress(address))