Exemplo n.º 1
0
 def on_event(self, ev: KeywordQueryEvent, ext: DRTExtension) -> BaseAction:
     try:
         if ev.get_query().endswith("`"):
             return SetUserQueryAction(ev.get_query().rstrip("`"))
         elif ev.get_argument() is None:
             return ext.get_favorites(ev)
         elif ev.get_argument().startswith("departures "):
             return ext.get_departures(
                 ev,
                 ev.get_argument().replace("departures ", "", 1))
         else:
             return ext.get_stops(ev, ev.get_argument())
     except DRTApiException as ex:
         return RenderResultListAction([self.make_error(ex)])
     except RequestException as ex:
         return RenderResultListAction([self.make_error(ex)])
Exemplo n.º 2
0
    def get_departures(self, ev: KeywordQueryEvent, arg: str) -> BaseAction:
        items = []

        stop = self.drt.stop(arg)
        items.append(self.make_departures_stop(stop, ev.get_query()))

        for departure in self.drt.departures(stop.id)[:5]:
            items.append(self.make_departures_departure(departure))

        return RenderResultListAction(items)
Exemplo n.º 3
0
 def get_stops(self, ev: KeywordQueryEvent, arg: str) -> BaseAction:
     items = []
     for stop in self.drt.stops(ev.get_argument())[:5]:
         items.append(self.make_stop(stop, ev.get_query()))
     return RenderResultListAction(items)
Exemplo n.º 4
0
 def get_favorites(self, ev: KeywordQueryEvent) -> BaseAction:
     return RenderResultListAction([
         self.make_favourite(stop, self.drt.departures(str(stop.id)),
                             ev.get_query()) for stop in self.fav_get()
     ])