Exemplo n.º 1
0
    def searchByLine(self, line):
        print("Searching by line...");
        bus = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.BUS);
        bus.setLine(line);
        niceResponse = self._serveRequest(bus);
        
        responseMessage = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.RESPONSE);
        try:
            infos = niceResponse.getStopList();
            responseMessage.setStatus(Response.STATUS_OK);
            responseMessage.setDescription(Response.STATUS_OK_DESC);
            
            stopList = list();
            for stop in infos:
                stopObject = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.STOP);
                stopObject.setObjectPropertiesFromAnmString(stop);
                stopList.append(stopObject.toString());
            
            responseMessage.setObjectsArray(stopList);
        except:
            responseMessage.clean();
            responseMessage.setStatus(Response.STATUS_ERROR);
            responseMessage.setDescription(niceResponse.getInfoPalina()[0]);

        return responseMessage.toString();
Exemplo n.º 2
0
 def _dispachRequest(self, jsonData):
     print jsonData;
     response_headers = [('Content-Type', 'application/json')];
     request = jsonData.split("=");
     print request;
     try:
         if request[0]=="stop_request":
             validatedRequest = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.STOP);
             validatedRequest.setObjectProperties(request[1]);
             response = AndroclickController().searchByStop(validatedRequest.getNumber());
         elif request[0]=="line_request":
             validatedRequest = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.BUS);
             validatedRequest.setObjectProperties(request[1]);
             response = AndroclickController().searchByLine(validatedRequest.getLine());
         elif request[0]=="location_request":
             validatedRequest = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.STOP);
             validatedRequest.setObjectProperties(request[1]);
             response = AndroclickController().searchByLocation(validatedRequest.getCounty(), validatedRequest.getStreet());
         else:
             responseObject = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.RESPONSE);
             responseObject.setStatus(Response.STATUS_ERROR);
             responseObject.setDescription("Bad request!");
             response = responseObject.toString();
     except ValidationException:
         responseObject = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.RESPONSE);
         responseObject.setStatus(Response.STATUS_ERROR);
         responseObject.setDescription("Bad JSON request");
         response = responseObject.toString();
     
     return response, response_headers; 
Exemplo n.º 3
0
 def searchByStop(self, number):
     print("Searching by stop...");
     stop = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.STOP);
     stop.setNumber(number);
     niceResponse = self._serveRequest(stop);
     infos = niceResponse.getInfoPalina();
     
     responseMessage = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.RESPONSE);
     
     if len(infos)>1:
         responseMessage.setStatus(Response.STATUS_OK);
         responseMessage.setDescription(Response.STATUS_OK_DESC);
         responseMessage.setAdditionalInfos(infos[0:2]);
         
         busList = list();
         for bus in infos[2:]:
             busObject = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.BUS);
             busObject.setObjectPropertiesFromAnmString(bus);
             busList.append(busObject.toString());
         
         responseMessage.setObjectsArray(busList);
     else:
         responseMessage.setStatus(Response.STATUS_ERROR);
         responseMessage.setDescription(infos[0]);
     
     return responseMessage.toString();
Exemplo n.º 4
0
    def searchByLine(self, line):
        print("Searching by line...")
        bus = AndroclickObjectFactory.getAndroclickObject(
            AndroclickObjectFactory.BUS)
        bus.setLine(line)
        niceResponse = self._serveRequest(bus)

        responseMessage = AndroclickObjectFactory.getAndroclickObject(
            AndroclickObjectFactory.RESPONSE)
        try:
            infos = niceResponse.getStopList()
            responseMessage.setStatus(Response.STATUS_OK)
            responseMessage.setDescription(Response.STATUS_OK_DESC)

            stopList = list()
            for stop in infos:
                stopObject = AndroclickObjectFactory.getAndroclickObject(
                    AndroclickObjectFactory.STOP)
                stopObject.setObjectPropertiesFromAnmString(stop)
                stopList.append(stopObject.toString())

            responseMessage.setObjectsArray(stopList)
        except:
            responseMessage.clean()
            responseMessage.setStatus(Response.STATUS_ERROR)
            responseMessage.setDescription(niceResponse.getInfoPalina()[0])

        return responseMessage.toString()
Exemplo n.º 5
0
    def searchByLocation(self, county, street):
        print("Searching by location...")
        stop = AndroclickObjectFactory.getAndroclickObject(
            AndroclickObjectFactory.STOP)
        stop.setCounty(county)
        stop.setStreet(street)
        niceResponse = self._serveRequest(stop)

        responseMessage = AndroclickObjectFactory.getAndroclickObject(
            AndroclickObjectFactory.RESPONSE)
        try:
            infos = niceResponse.getStopList()
            responseMessage.setStatus(Response.STATUS_OK)
            responseMessage.setDescription(Response.STATUS_OK_DESC)

            stopList = list()
            for stop in infos:
                stopObject = AndroclickObjectFactory.getAndroclickObject(
                    AndroclickObjectFactory.STOP)
                stopObject.setObjectPropertiesFromAnmString(stop)
                stopList.append(stopObject.toString())

            responseMessage.setObjectsArray(stopList)
        except:
            responseMessage.clean()
            responseMessage.setStatus(Response.STATUS_ERROR)
            responseMessage.setDescription(niceResponse.getInfoPalina()[0])

        return responseMessage.toString()
Exemplo n.º 6
0
    def searchByStop(self, number):
        print("Searching by stop...")
        stop = AndroclickObjectFactory.getAndroclickObject(
            AndroclickObjectFactory.STOP)
        stop.setNumber(number)
        niceResponse = self._serveRequest(stop)
        infos = niceResponse.getInfoPalina()

        responseMessage = AndroclickObjectFactory.getAndroclickObject(
            AndroclickObjectFactory.RESPONSE)

        if len(infos) > 1:
            responseMessage.setStatus(Response.STATUS_OK)
            responseMessage.setDescription(Response.STATUS_OK_DESC)
            responseMessage.setAdditionalInfos(infos[0:2])

            busList = list()
            for bus in infos[2:]:
                busObject = AndroclickObjectFactory.getAndroclickObject(
                    AndroclickObjectFactory.BUS)
                busObject.setObjectPropertiesFromAnmString(bus)
                busList.append(busObject.toString())

            responseMessage.setObjectsArray(busList)
        else:
            responseMessage.setStatus(Response.STATUS_ERROR)
            responseMessage.setDescription(infos[0])

        return responseMessage.toString()
Exemplo n.º 7
0
    def _dispachRequest(self, jsonData):
        print jsonData
        response_headers = [('Content-Type', 'application/json')]
        request = jsonData.split("=")
        print request
        try:
            if request[0] == "stop_request":
                validatedRequest = AndroclickObjectFactory.getAndroclickObject(
                    AndroclickObjectFactory.STOP)
                validatedRequest.setObjectProperties(request[1])
                response = AndroclickController().searchByStop(
                    validatedRequest.getNumber())
            elif request[0] == "line_request":
                validatedRequest = AndroclickObjectFactory.getAndroclickObject(
                    AndroclickObjectFactory.BUS)
                validatedRequest.setObjectProperties(request[1])
                response = AndroclickController().searchByLine(
                    validatedRequest.getLine())
            elif request[0] == "location_request":
                validatedRequest = AndroclickObjectFactory.getAndroclickObject(
                    AndroclickObjectFactory.STOP)
                validatedRequest.setObjectProperties(request[1])
                response = AndroclickController().searchByLocation(
                    validatedRequest.getCounty(), validatedRequest.getStreet())
            else:
                responseObject = AndroclickObjectFactory.getAndroclickObject(
                    AndroclickObjectFactory.RESPONSE)
                responseObject.setStatus(Response.STATUS_ERROR)
                responseObject.setDescription("Bad request!")
                response = responseObject.toString()
        except ValidationException:
            responseObject = AndroclickObjectFactory.getAndroclickObject(
                AndroclickObjectFactory.RESPONSE)
            responseObject.setStatus(Response.STATUS_ERROR)
            responseObject.setDescription("Bad JSON request")
            response = responseObject.toString()

        return response, response_headers
Exemplo n.º 8
0
    def _sendRequest(self, requestData=None, currentCookie=None):
        connection = urllib2.build_opener();
        
        connection.addheaders = [(USER_AGENT_KEY, USER_AGENT_VALUE)];
        
        if currentCookie != None:
            connection.addheaders.extend([(COOKIE_KEY, currentCookie)]);
        
        try:
            response = connection.open(SERVER_URL, requestData);
        except urllib2.HTTPError as httpException:
            raise AnmException("ANMProvider.py - Remote server error: " + str(httpException.code));# + " " + httpException.reason);
        except Exception as generalException:
            raise AnmException("ANMProvider.py - Local error: " + str(generalException.reason));
        
        connection.close();
        
        return response;
                
if __name__ == "__main__":
    bus = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.BUS);
    bus.setLine('r2');
    requestedObject = ANMProvider().androclickFlow(bus);
    print(requestedObject);
    stop = AndroclickObjectFactory.getAndroclickObject(AndroclickObjectFactory.STOP);
    stop.setNumber('3352');
    requestedObject = ANMProvider().androclickFlow(stop);
    print(requestedObject);

            
Exemplo n.º 9
0
        if currentCookie != None:
            connection.addheaders.extend([(COOKIE_KEY, currentCookie)])

        try:
            response = connection.open(SERVER_URL, requestData)
        except urllib2.HTTPError as httpException:
            raise AnmException("ANMProvider.py - Remote server error: " +
                               str(httpException.code))
            # + " " + httpException.reason);
        except Exception as generalException:
            raise AnmException("ANMProvider.py - Local error: " +
                               str(generalException.reason))

        connection.close()

        return response


if __name__ == "__main__":
    bus = AndroclickObjectFactory.getAndroclickObject(
        AndroclickObjectFactory.BUS)
    bus.setLine('r2')
    requestedObject = ANMProvider().androclickFlow(bus)
    print(requestedObject)
    stop = AndroclickObjectFactory.getAndroclickObject(
        AndroclickObjectFactory.STOP)
    stop.setNumber('3352')
    requestedObject = ANMProvider().androclickFlow(stop)
    print(requestedObject)