コード例 #1
0
 def test_when_only_outside_range_and_after_requested_are_available(self):
     arrival = ArrivalResult(12345,
                             111,
                             None,
                             outside_range=2,
                             after_requested=16)
     message = explain(arrival)
     self.assertEqual(
         "The next <text>111</text> will come in 2 minutes time, and the one after that will come in 16 minutes time, that's after your requested time",
         message)
コード例 #2
0
 def test_when_within_range_is_available(self):
     arrival = ArrivalResult(12345, 111, 7)
     expected_results = [
         "Bus <text>111</text> will arrive at bus stop <text>12345</text> in 7 minutes time",
         "You have to be at bus stop <text>12345</text> in 7 minutes to catch bus <text>111</text>"
     ]
     for index in range(0, len(expected_results)):
         with self.subTest(i=index):
             message = explain(arrival, index)
             self.assertEqual(expected_results[index], message)
コード例 #3
0
ファイル: telegrambot.py プロジェクト: alfredp77/buspy
def check_and_send_message(chat, checker):
    result = checker.time_to_be_at_bus_stop()
    can_use_result = (result.within_range
                      or (result.outside_range
                          and result.outside_range_may_be_acceptable)
                      or (not result.outside_range and result.after_requested))

    if can_use_result:
        message = clean_message(explain(result))
        chat.send(message)
        return True
    return False
コード例 #4
0
ファイル: dialogflow.py プロジェクト: gunawanwu/buspyfinal
def handle_getBusArrivalTimeIntent(req):
    busno = req["queryResult"]["parameters"]["BusNo"]
    busstop = req["queryResult"]["parameters"]["BusStopNo"]
    departuretime_original = req["queryResult"]["outputContexts"][0][
        "parameters"]["DepartureTime.original"]
    departuretime = req["queryResult"]["parameters"]["DepartureTime"]

    checker, resp_text = build_checker(
        busstop,
        busno,
        departuretime,
        departuretime_original,
        code_formatter=lambda x:
        f'<say-as interpret-as="characters">{x}</say-as>')
    if checker:
        result = checker.time_to_be_at_bus_stop()
        resp_text = explain(result)
        if resp_text:
            resp_text = resp_text.replace(
                '<text>', '<say-as interpret-as="characters">').replace(
                    '</text>', '</say-as>')
        else:
            resp_text = "I cannot find bus arrival time near to your departure time. Please try again later"
    return resp_text
コード例 #5
0
 def test_bus_is_coming_soon(self):
     arrival = ArrivalResult(12345, 111, 0)
     message = explain(arrival)
     self.assertEqual(
         "Bus <text>111</text> is arriving at bus stop <text>12345</text>",
         message)
コード例 #6
0
 def test_when_only_outside_range_is_available(self):
     arrival = ArrivalResult(12345, 111, None, outside_range=3)
     message = explain(arrival)
     self.assertEqual(
         "The closest available <text>111</text> for your requested time will come in 3 minutes time",
         message)
コード例 #7
0
 def test_when_only_after_requested_is_available(self):
     arrival = ArrivalResult(12345, 111, None, after_requested=12)
     message = explain(arrival)
     self.assertEqual(
         "The only available <text>111</text> will come after your requested time, 12 minutes from now",
         message)
コード例 #8
0
 def test_bus_is_coming_soon_and_next_bus_available(self):
     arrival = ArrivalResult(12345, 111, 0, after_requested=5)
     message = explain(arrival)
     self.assertEqual(
         "Bus <text>111</text> is arriving at bus stop <text>12345</text>, and the next one will arrive in 5 minutes",
         message)