示例#1
0
    def SearchCabwise(
            self, lat, lon, optype=None, wc=None, radius=None,
            name=None, maxResults=None, legacy_format=True,
            twentyfour_seven=True):
        url = self.base_url + "Cabwise/Search"
        extra_params = {}
        extra_params["lat"] = validate_input(lat, float, "lat")
        extra_params["lon"] = validate_input(lon, float, "lon")

        if radius:
            extra_params["radius"] = validate_input(radius, float, "radius")
        if maxResults:
            extra_params["maxResults"] = validate_input(
                maxResults, int, "maxResults"
            )
        if twentyfour_seven is not None:
            extra_params["twentyfour_seven"] = validate_input(
                twentyfour_seven, bool, "twentyfour_seven"
            )
        response = self._Request(
            url, extra_params=extra_params, http_method="GET")
        data = self._CheckResponse(
            response.json()["Operators"]["OperatorList"])

        return [Cabwise.fromJSON(c) for c in data]
示例#2
0
    def GetLinesByModeServiceType(self, modes, serviceType):
        url = self.base_url + "Line/Mode/{0}/Route/"
        extra_params = {}
        if serviceType in ["Regular", "Night"]:
            extra_params["serviceTypes"] = validate_input(
                serviceType, str, "serviceType"
            )
        response = self._Request(
            url.format(validate_input(modes, list, "modes")),
            extra_params=extra_params, http_method="GET"
        )
        data = self._CheckResponse(response.json())

        return [Line.fromJSON(l) for l in data]
示例#3
0
    def GetLinesByIDServiceType(self, ids, serviceType):
        url = self.base_url + "Line/%s/Route/"
        extra_params = {}
        if serviceType in ["Regular", "Night"]:
            extra_params["serviceTypes"] = validate_input(
                serviceType, str, "serviceType"
            )
        response = self._Request(
            url.format(validate_input(ids, list, "ids")),
            extra_params=extra_params, http_method="GET"
        )
        data = self._CheckResponse(response.json())
        if isinstance(data, dict):
            data = [data]

        return [Line.fromJSON(l) for l in data]
示例#4
0
    def GetLinesByMode(self, modes):
        url = self.base_url + "Line/Mode/{0}/"
        response = self._Request(
            url.format(validate_input(modes, list, "modes")),
            http_method="GET"
        )
        data = self._CheckResponse(response.json())

        return [Line.fromJSON(l) for l in data]
示例#5
0
    def GetLineRouteSequence(
        self, _id, direction, serviceTypes, excludeCrowding
    ):
        url = self.base_url + "Line/{0}/Route/Sequence/{1}/"

        extra_params = {}
        if serviceTypes in ["Regular", "Night"]:
            extra_params["serviceTypes"] = validate_input(
                serviceTypes, str, "serviceType"
            )
        if excludeCrowding is not None:
            extra_params["excludeCrowding"] = validate_input(
                excludeCrowding, bool, "excludeCrowding")
        response = self._Request(
            url.format(validate_input(_id, str, "_id"),
                       validate_input(direction, str, "direction")),
            extra_params=extra_params, http_method="GET"
        )
        data = self._CheckResponse(response.json())
        return LineRouteSequence.fromJSON(data)
示例#6
0
    def GetLinesByID(self, ids):
        url = self.base_url + "Line/{0}/"
        response = self._Request(
            url.format(",".join(validate_input(ids, list, "ids"))),
            http_method="GET"
        )
        data = self._CheckResponse(
            response.json()
        )

        return [Line.fromJSON(l) for l in data]
示例#7
0
    def SearchJourneyPlanner(
            self, _from, to, via=None, nationalSearch=False, date=None,
            time=None, timels=None, journeyPreference=None, mode=None,
            accessibilityPreference=None, fromName=None, toName=None,
            viaName=None, maxTransferMinutes=None, maxWalkingMinutes=None,
            walkingSpeed=None, cyclePreference=None, adjustment=None,
            bikeProficiency=None, alternativeCycle=None,
            alternativeWalking=None, useMultiModalCall=None,
            walkingOptimsation=False, taxiOnlyTrip=False):
        url = self.base_url + "Journey/JourneyResults/{0}/to/{1}"

        extra_params = {}
        if via is not None:
            extra_params["via"] = validate_input(via, str, "via")
        if nationalSearch is not None:
            extra_params["nationalSearch"] = validate_input(
                nationalSearch, bool, "nationalSearch"
            )
        if date is not None:
            extra_params["date"] = validate_input(date, str, "data")
        if time is not None:
            extra_params["time"] = validate_input(time, str, "time")
        if timels in ["Arriving", "Departing"]:
            extra_params["timels"] = timels
        if journeyPreference in ["LeastInterchange", "LeastWalking",
                                 "leastTime"]:
            extra_params["journeyPreference"] = journeyPreference
        if mode is not None:
            if isinstance(mode, (tuple, list)):
                extra_params["mode"] = ','.join(
                    [validate_input(m) for m in mode])
            else:
                extra_params["mode"] = validate_input(mode, str, "mode")
        if (accessibilityPreference in
            ["noSolidStairs", "noEscalators", "noElavators",
             "stepFreeToVehicle", "stepFreeToPlatform"]):
            extra_params["accessibilityPreference"] = accessibilityPreference
        if fromName is not None:
            extra_params["fromName"] = validate_input(
                fromName, str, "fromName")
        if toName is not None:
            extra_params["toName"] = validate_input(toName, str, "toName")
        if viaName is not None:
            extra_params["viaName"] = validate_input(viaName, str, "viaName")
        if maxTransferMinutes is not None:
            extra_params["maxTransferMinutes"] = str(validate_input(
                maxTransferMinutes, int, "maxTransferMinutes")
            )
        if maxWalkingMinutes is not None:
            extra_params["maxWalkingMinutes"] = str(
                validate_input(maxWalkingMinutes, int, "maxWalkingMinutes")
            )
        if walkingSpeed in ["Slow", "Average", "Fast"]:
            extra_params["walkingSpeed"] = walkingSpeed
        if (cyclePreference in
                ["AllTheWay", "LeaveAtStation", "TakeOnTransport",
                 "CycleHire"]):
            extra_params["cyclePreference"] = cyclePreference
        if adjustment in ["TripFirst", "TripLast"]:
            extra_params["adjustment"] = adjustment
        if bikeProficiency in ["Easy", "Moderate", "Fast"]:
            extra_params["bikeProficiency"] = bikeProficiency
        if alternativeCycle is not None:
            extra_params["alternativeCycle"] = validate_input(
                alternativeCycle, bool, "alternativeCycle")
        if useMultiModalCall is not None:
            extra_params["useMultiModalCall"] = validate_input(
                useMultiModalCall, bool, "useMultiModalCall")
        if walkingOptimsation is not None:
            extra_params["walkingOptimsation"] = validate_input(
                walkingOptimsation, bool, "walkingOptimsation")
        if taxiOnlyTrip is not None:
            extra_params["taxiOnlyTrip"] = validate_input(
                taxiOnlyTrip, bool, "taxiOnlyTrip")

        response = self._Request(
            url.format(
                validate_input(_from, str, "_from"),
                validate_input(to, str, "to")),
            extra_params=extra_params, http_method="GET")
        data = self._CheckResponse(
            response.json()
        )

        if "DisambiguationResult" in data["$type"]:
            return JourneyDisambiguation.fromJSON(data)
        else:
            return JourneyPlanner.fromJSON(data)