Ejemplo n.º 1
0
def generate_schedule(depart_date, arrival_date, route_list, refresh_period, days_offset=3):

    d0_range = iterdates(
        depart_date - timedelta(days=days_offset),
        depart_date + timedelta(days=days_offset + 1),
    )

    d1_range = iterdates(
        arrival_date - timedelta(days=days_offset),
        arrival_date + timedelta(days=days_offset + 1),
    )

    for d0 in d0_range:
        for airline, (ap0, ap1) in route_list:
            yield (d0, airline, ap0, ap1, refresh_period)

    for d1 in d1_range:
        for airline, (ap0, ap1) in route_list:
            yield (d1, airline, ap1, ap0, refresh_period)
Ejemplo n.º 2
0
def main():
    today = date(2016, 1, 1)  # date.today()
    plan_period = timedelta(days=365)
    min_travel_days = 3
    for start_day in iterdates(today, today + plan_period):
        for travel_days in range(min_travel_days, 30):
            end_date = start_day + timedelta(days=travel_days + 1)
            if is_holiday(end_date - timedelta(days=1)) and \
                    is_holiday(end_date):
                continue

            travel_days = list(iterdates(start_day, end_date))
            holiday_count = sum((1 for day in travel_days if is_holiday(day)))
            workday_count = len(travel_days) - holiday_count
            if workday_count > holiday_count:
                continue
            if holiday_count > workday_count:
                print "[%s, %s] 请%d天休%d天 (%.2f %%)" % (
                    start_day,
                    end_date - timedelta(days=1),
                    workday_count,
                    (workday_count + holiday_count),
                    (100.0 * workday_count / (workday_count + holiday_count))
                )
Ejemplo n.º 3
0
def main(argv):
    if len(argv) != 6:
        print "usage: python this.py airasia PEK KUL 2015-10-01 2016-01-01"
        return 1

    airline = argv[1]
    dep = argv[2]  # PEK
    arr = argv[3]  # KUL
    begin_date = datetime.strptime(argv[4], "%Y-%m-%d").date()
    end_date = datetime.strptime(argv[5], "%Y-%m-%d").date()

    for date_ in iterdates(begin_date, end_date):
        price = get_lowest_price_from_remote(airline, dep, arr, date_)

        if price is None:
            continue

        print "%s (%s) %s-%s CNY: %d" % (date_.strftime("%Y-%m-%d"), WEEDDAYS[date_.weekday()], dep, arr, price)
Ejemplo n.º 4
0
def main(argv):
    if len(argv) != 6:
        print 'usage: python this.py airasia PEK KUL 2015-10-01 2016-01-01'
        return 1

    airline = argv[1]
    dep = argv[2]  # PEK
    arr = argv[3]  # KUL
    begin_date = datetime.strptime(argv[4], "%Y-%m-%d").date()
    end_date = datetime.strptime(argv[5], "%Y-%m-%d").date()

    for date_ in iterdates(begin_date, end_date):
        price = get_lowest_price_from_remote(airline, dep, arr, date_)

        if price is None:
            continue

        print '%s (%s) %s-%s CNY: %d' % (
            date_.strftime("%Y-%m-%d"),
            WEEDDAYS[date_.weekday()],
            dep,
            arr,
            price,
        )