Example #1
0
    def get_bus_info(self, query, lat, lon, full_info, hide_text=True):
        user_loc = None
        if lat and lon:
            user_loc = UserLoc(float(lat), float(lon))
        routes_info = parse_routes(query)
        is_fraud = not full_info and len(routes_info.bus_routes) > 25

        result = self.cds.bus_request(routes_info, user_loc=user_loc, short_format=True)
        return {'q': query,
                'server_time': datetime.datetime.now(),
                'text': '' if hide_text else result[0],
                'buses': [(eliminate_numbers(x[0]._asdict(), full_info, is_fraud),
                           x[1]._asdict() if x[1] and not is_fraud else {}) for x
                          in result[1]]}
Example #2
0
 def get_bus_info(self, query, lat, lon):
     user_loc = None
     if lat and lon:
         user_loc = UserLoc(float(lat), float(lon))
     result = self.cds.bus_request(parse_routes(query),
                                   user_loc=user_loc,
                                   short_format=True)
     return {
         'q':
         query,
         'text':
         result[0],
         'buses': [(x[0]._asdict(), x[1]._asdict() if x[1] else {})
                   for x in result[1]]
     }
Example #3
0
    def show_arrival(self, update, lat, lon):
        user = update.message.from_user

        self.track(TgEvent.NEXT, update, lat, lon)
        self.logger.info(f"User: {user} {lat}, {lon}")
        matches = self.cds.matches_bus_stops(lat, lon)
        user_loc = UserLoc(lat, lon)
        settings = self.user_settings.get(user.id, {})
        settings['user_loc'] = user_loc
        self.user_settings[user.id] = settings
        bus_routes = settings.get('route_settings')
        search_result = SearchResult(bus_routes=(bus_routes if bus_routes else tuple()))
        arrival_info = self.cds.next_bus_for_matches(tuple(matches), search_result)
        self.logger.debug(f"next_bus_for_matches {user} {arrival_info}")
        update.message.reply_text(self.get_text_from_arrival_info(arrival_info), parse_mode='Markdown',
                                  reply_markup=ReplyKeyboardRemove())