示例#1
0
    def parseV4(js, city):
        for feature in js['features']:
            properties = feature['properties']
            station = Station()

            voie = properties.get('NOM_VOIE')
            voie = "" if not voie else voie
            compl = properties.get("COMPL_LOC")
            compl = "" if not compl else compl
            name = voie + " " + compl
            station.setName(name if name != " " else None)

            st_id = feature.get('id')
            station.setId(int(st_id) if st_id else st_id)

            coords = feature.get('geometry')
            if coords and coords.get('coordinates'):
                coords = coords.get('coordinates')
                station.setLattitude(float(coords[1]))
                station.setLongitude(float(coords[0]))
            total = properties.get('NBR_PT_ACC')
            station.setTotal(int(total) if total else total)
            avail = properties.get('NBR_VELO')
            station.setAvailable(int(avail) if avail else avail)
            if total and avail:
                free = int(total) - int(avail)
                station.setFree(free)

            city.addStation(station)
def test_get_stations_from_response():
    json = {
        "payload": [
            {
                "code": "BVB",
                "namen": {
                    "lang": "Aachen Hbf",
                }
            }
        ]
    }
    

    response = mock.Mock()
    response.status_code = 200
    response.json = mock.Mock(return_value=json)

    expected_result = [
        Station(
            name="Aachen Hbf",
            code="BVB"
        )
    ]
    result = get_stations_from_response(response)

    assert result == expected_result
示例#3
0
    def parseDecaux(js, city):

        for record in js['records']:
            properties = record['fields']
            station = Station()

            station.setName(properties.get('name'))
            st_id = properties.get('number')
            station.setId(int(st_id) if st_id else st_id)

            coords = properties.get('position')
            if coords:
                station.setLattitude(float(coords[0]))
                station.setLongitude(float(coords[1]))

            total = properties.get('bike_stands')
            station.setTotal(int(total) if total else total)
            avail = properties.get('available_bikes')
            station.setAvailable(int(avail) if avail else avail)
            free = properties.get('available_bike_stands')
            station.setFree(int(free) if free else free)
            card = properties.get('banking')
            station.setCardPaiement(card != "False" if card else card)

            city.addStation(station)
    def create_station(self, fm_band):
        if not self.name or self.name.isspace():
            return jsonify({
                "message":"name is required"
            }),400

        if type(self.name) != str:
            return jsonify({
                "message": "name should be a string"
            }),400
        if not self.address or self.address.isspace():
            return jsonify({
                "message":"address is required"
            }),400

        if type(self.address) != str:
            return jsonify({
                "message": "address should be a string"
            }),400
        
        station_model = Station(self.name,self.address)
        station = station_model.create_station(fm_band)


        return jsonify({
            "message":"station created successfully",
            "station" :station
        }), 201
 def add_stations(self, min_capacity, max_capacity, number):
     for i in range(number):
         self.stations.append(
             Station(
                 capacity=random.randint(min_capacity, max_capacity),
                 radius=0.85,
                 faker=self.faker,
             ))
示例#6
0
    def _build_line_data(self, station_df):
        """Constructs all stations on the line"""
        stations = station_df["station_name"].unique()

        station_data = station_df[station_df["station_name"] == stations[0]]
        line = [
            Station(station_data["station_id"].unique()[0], stations[0],
                    self.color)
        ]
        prev_station = line[0]
        for station in stations[1:]:
            station_data = station_df[station_df["station_name"] == station]
            new_station = Station(station_data["station_id"].unique()[0],
                                  station, self.color, prev_station)
            prev_station.dir_b = new_station
            prev_station = new_station
            line.append(new_station)
        return line
示例#7
0
def create_new_station(contacted, stationname, located):

    station = Station()
    station.contact = contacted
    station.name = stationname
    station.location = located
    station.save()
    return jsonify({
        "message": "Successfully make a new item."
        }), 200
    def get_stations():
        model  = Station("","")

        stations = model.get_stations()

        if len(stations) == 0:
            return jsonify({
                "message":"sorry! no statiosn were found"
            })

        return jsonify({
            "message":"successful",
            "stations":stations
        })
示例#9
0
    def parseV5(js, city):
        stations = js['data']['stations']
        for properties in stations:
            station = Station()
            station.setName(properties.get('name'))
            st_id = properties.get('station_id')
            station.setId(int(st_id) if st_id else st_id)
            lat = properties.get('lat')
            station.setLattitude(float(lat) if lat else lat)
            lon = properties.get('lon')
            station.setLongitude(float(lon) if lon else lon)
            total = properties.get('capacity')
            station.setTotal(int(total) if total else total)

            city.addStation(station)
示例#10
0
    def parseV3(js, city):

        for record in js['records']:
            properties = record['fields']
            station = Station()

            station.setName(properties.get('name'))
            station.setId(properties.get('recordid'))
            coords = properties.get('geo_point_2d')
            if coords:
                station.setLattitude(float(coords[1]))
                station.setLongitude(float(coords[0]))
            total = properties.get('capacity')
            station.setTotal(int(total) if total else total)

            city.addStation(station)
示例#11
0
    def _parse(self):
        self.ovo = self.param('ovo')

        for tds in self.tr_tds(1, from_index=1):
            id = int(tds[0].text())

            if not Station.get(id=id):
                StationDirty(
                    id=id,
                    address=StationParser.clear_html(tds[1].html()),
                    bound=tds[2].text(),
                )

                Station(id=id, ovo_id=self.ovo.id)

        self.ovo.processed = True
def test_get_station_from_json():
    json = {
        "code": "BVB",
        "namen": {
            "lang": "Aachen Hbf",
        }
    }

    expected_result = Station(
        name="Aachen Hbf",
        code="BVB"
    )

    result = get_station_from_json(json)

    assert result == expected_result
示例#13
0
    def parseV2(js, city):

        for record in js['records']:
            properties = record['fields']
            station = Station()

            station.setName(properties.get('nom'))
            st_id = properties.get('idstation')
            station.setId(int(st_id) if st_id else st_id)
            coords = properties.get('coordonnees')
            if coords:
                station.setLattitude(float(coords[0]))
                station.setLongitude(float(coords[1]))
            total = properties.get('nombreemplacementsactuels')
            station.setTotal(int(total) if total else total)
            avail = properties.get('nombrevelosdisponibles')
            station.setAvailable(int(avail) if avail else avail)
            free = properties.get('nombreemplacementsdisponibles')
            station.setFree(int(free) if free else free)

            city.addStation(station)
示例#14
0
    def parseV1(js, city):

        for feature in js['features']:
            properties = feature['properties']
            station = Station()
            station.setName(properties.get('name'))
            st_id = properties.get('number')
            station.setId(int(st_id) if st_id else st_id)
            lat = properties.get('lat')
            station.setLattitude(float(lat) if lat else lat)
            lon = properties.get('lng')
            station.setLongitude(float(lon) if lon else lon)
            total = properties.get('bike_stands')
            station.setTotal(int(total) if total else total)
            avail = properties.get('available_bikes')
            station.setAvailable(int(avail) if avail else avail)
            free = properties.get('available_bike_stands')
            station.setFree(int(free) if free else free)
            card = properties.get('banking')
            station.setCardPaiement(card == "true" if card else card)

            city.addStation(station)
    def get_station(name):

        if not name or name.isspace():
            return jsonify({
                "message":"name is required"
            }),400

        if type(name) != str:
            return jsonify({
                "message": "name should be a string"
            }),400

        station_model = Station("","")
        my_station = station_model.get_station(name)
        if my_station is None:
            return jsonify({
                "message":"station was not found"
            }),200
        
        return jsonify({
            "message":"successful",
            "station":my_station
        }), 200
示例#16
0
def get_all_stations():
    try:
        with open('stations.txt', 'r') as f:
            stations = pickle.load(f)
            return stations
    except IOError:
        pass
    raw_data = get(
        'https://kyfw.12306.cn/otn/resources/js/framework/station_name.js')
    match = re.search('\'(.*)\'', raw_data)
    content = match.group(1)
    raw_stations = content.split('@')
    stations = []
    for station in raw_stations:
        if not station:
            continue
        sta_attrs = station.split('|')
        station_obj = Station(sta_attrs[1], sta_attrs[2], sta_attrs[3])
        stations.append(station_obj)

    with open('stations.txt', 'wb') as f:
        pickle.dump(stations, f)
    return stations
示例#17
0
    def parse(content, city):
        root = ET.fromstring(content)
        elements = root[0]

        for element in elements:
            station = Station()
            properties = element.attrib

            station.setName(properties.get('na'))
            st_id = properties.get('id')
            station.setId(int(st_id) if st_id else st_id)
            lat = properties.get('la')
            station.setLattitude(float(lat) if lat else lat)
            lon = properties.get('lg')
            station.setLongitude(float(lon) if lon else lon)
            total = properties.get('to')
            station.setTotal(int(total) if total else total)
            avail = properties.get('av')
            station.setAvailable(int(avail) if avail else avail)
            free = properties.get('fr')
            station.setFree(int(free) if free else free)

            city.addStation(station)
示例#18
0
 def get_station_data(self):
     return [
         Station(station['name'], station['id'], station['coordinates'],
                 station['capacity']) for station in self.stations
     ]
示例#19
0
 def add_station(self, stations, name, uri):
     station = Station()
     station.init(name, uri)
     stations.add_station(station)