Exemple #1
0
    def test_add_dup(self):
        flight_date = date(2016, 10, 1)
        origin = "PEK"
        destination = "KUL"
        airline = "airasia"
        now_ts = int(time.time())

        ts1 = now_ts - 1000
        rec_id1 = LowestPriceHistory.update_price(flight_date, origin,
                                                  destination,
                                                  Decimal("1024.25"), airline,
                                                  ts1)
        p = LowestPriceHistory.get_latest_price(flight_date, origin,
                                                destination)
        assert p.price_cny == Decimal("1024.25")
        assert p.first_seen_at == p.last_seen_at == ts1

        ts2 = now_ts - 500
        rec_id2 = LowestPriceHistory.update_price(flight_date, origin,
                                                  destination,
                                                  Decimal("1024.25"), airline,
                                                  ts2)
        assert rec_id1 == rec_id2

        p2 = LowestPriceHistory.get_latest_price(flight_date, origin,
                                                 destination)

        assert p2.price_cny == Decimal("1024.25")
        assert p2.first_seen_at == ts1
        assert p2.last_seen_at == ts2
    def test_add_dup(self):
        flight_date = date(2016, 10, 1)
        origin = "PEK"
        destination = "KUL"
        airline = "airasia"
        now_ts = int(time.time())

        ts1 = now_ts - 1000
        rec_id1 = LowestPriceHistory.update_price(
            flight_date, origin, destination, Decimal("1024.25"), airline,
            ts1
        )
        p = LowestPriceHistory.get_latest_price(
            flight_date, origin, destination
        )
        assert p.price_cny == Decimal("1024.25")
        assert p.first_seen_at == p.last_seen_at == ts1

        ts2 = now_ts - 500
        rec_id2 = LowestPriceHistory.update_price(
            flight_date, origin, destination, Decimal("1024.25"), airline,
            ts2
        )
        assert rec_id1 == rec_id2

        p2 = LowestPriceHistory.get_latest_price(
            flight_date, origin, destination
        )

        assert p2.price_cny == Decimal("1024.25")
        assert p2.first_seen_at == ts1
        assert p2.last_seen_at == ts2
Exemple #3
0
def fetch_lowest_price(airline, dep_code, arr_code, departure_date,
                       cache_expiration):
    latest_price = LowestPriceHistory.get_latest_price(
        departure_date, dep_code, arr_code
    )
    if latest_price:
        if time.time() - latest_price.last_seen_at < cache_expiration:
            return latest_price.price_cny

    price = get_lowest_price_from_remote(
        airline, dep_code, arr_code, departure_date
    )
    if price is None:
        return
    LowestPriceHistory.update_price(
        departure_date, dep_code, arr_code, price, airline
    )
    return price
Exemple #4
0
def price_history():
    r = LowestPriceHistory.list()
    return jsonify({"status": "ok", "response": r})
Exemple #5
0
def price_history():
    r = LowestPriceHistory.list()
    return jsonify({
        "status": "ok",
        "response": r
    })