def getCities(self, state, format=None):
     state = self.getOneState(state=state)
     if state is not None:
         try:
             file = open(
                 os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
                 + '/static/json/cities.json', 'r', 1)
         except:
             print("OOPs! " + str(sys.exc_info()[0]) + "Occured.")
             return
         else:
             self.cities = []
             try:
                 data = json.load(file)
             except:
                 print("OOPs! " + str(sys.exc_info()[0]) + "Occured.")
                 return
             for dictData in data['cities']:
                 if dictData['state_id'].lower() == state['id'].lower():
                     self.cities.append(dictData)
             self.cities = sorted(self.cities,
                                  key=lambda item: item['name'])
             file.close()
     else:
         return "Invalid User State Location"
Beispiel #2
0
    def getAllStates(self):
        if self.error:
            return self.error

        self.states = []
        data = {}
        data = json.load(self.stateFile)
        for dictData in data['states']:
            dictData['icon'] = getHostName() + dictData['icon']
            self.states.append(dictData)
        self.states = sorted(self.states, key=lambda item: item['name'])
        return self.states
Beispiel #3
0
    def makeQuickState(self, nearStates):
        if self.error:
            return self.error

        self.states = []
        data = json.load(self.stateFile)
        for dictData in data['states']:
            for nearState in nearStates:
                if nearState.lower() == dictData['name'].lower():
                    dictData['quick'] = True
            dictData['icon'] = getHostName() + dictData['icon']
            self.states.append(dictData)
        self.states = sorted(self.states, key=lambda item: item['name'])
        return self.states
 def get(self, request, format=None):
     try:
         file = open(
             os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +
             '/static/json/specialities.json', 'r', 1)
     except:
         return Response("Specialities File is Missing.")
     else:
         # print(request.META)
         try:
             data = json.load(file)
         except:
             print("OOPs! " + str(sys.exc_info()[0]) + "Occured.")
             return
         file.close()
         for dictData in data['specialities']:
             dictData['icon'] = request.META[
                 'wsgi.url_scheme'] + '://' + request.META[
                     'HTTP_HOST'] + dictData['icon']
         return Response(data['specialities'])
    def getStates(self, countryID, format=None):
        try:
            file = open(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +
                '/static/json/states.json', 'r', 1)
        except:
            self.error = {
                "status": True,
                "message": "State Not Found in the list."
            }
        else:
            self.states = []

            try:
                data = json.load(file)
            except:
                print("OOPs! " + str(sys.exc_info()[0]) + "Occured.")
                return
            for dictData in data['states']:
                self.states.append(dictData)

            self.states = sorted(self.states, key=lambda item: item['name'])
            file.close()