Extract current routine information from page.

    :param page: crawled page.
    :param stations: bus stations list. See `~extract_stations`.
960945
def extract_current_routine(page, stations):
    '''
    '''
    current_routines = CURRENT_ROUTINE_PATTERN.findall(page.text())
    if not current_routines:
        return

    terminal_station = stations['stations'][-1]
    for routine in current_routines:
        if _(routine[0]) == terminal_station:
            distance = int(routine[1])
    stations_to_this_dir = stations['terminal'][terminal_station]

    waiting_station = _(page('.now .stateName').val())
    idx = stations_to_this_dir.index(waiting_station)
    bus_station = stations_to_this_dir[idx - distance + 1]

    return {
        'destinate_station': terminal_station,
        'bus_station': bus_station,
        'waiting_station': waiting_station,
        'distance': distance
    }
65158
def get_page(self, page_number):
        

        if page_number:
            kwargs = dict(self._list_kwargs)
            kwargs['limit'] = self.limit
            kwargs['page'] = page_number

            return self._controller.list(**kwargs)
491260
def for_page(self, page, per_page):
        
        start = (page - 1) * per_page

        return self[start:start + per_page]
596179
def get_stations(self):
        

        status, data = self.http_client.get_json(
            STATIONS_URI,
            params={'appid': self.API_key},
            headers={'Content-Type': 'application/json'})
        return [self.stations_parser.parse_dict(item) for item in data]
833710
def stations_iter(self, *, page_size=250):
		

		start_token = None

		while True:
			response = self._call(
				mc_calls.RadioStation,
				max_results=page_size,
				start_token=start_token
			)
			yield response.body.get('data', {}).get('items', [])

			start_token = response.body.get('nextPageToken')
			if start_token is None:
				break
911941
def getsystemhooks(self, page=1, per_page=20):
        
        data = {'page': page, 'per_page': per_page}

        request = requests.get(
            self.hook_url, params=data, headers=self.headers,
            verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)

        if request.status_code == 200:
            return request.json()
        else:
            return False
823794
def get_page(self, page_id):
        
        try:
            result = self._request('/getpage/',
                                   {'pageid': page_id})
            return TildaPage(**result)
        except NetworkError:
            return []
1278514
def get_children_for_page(self, page):
        """"""
        if self.max_levels == 1:
            # If there's only a single level of pages to display, skip the
            # dict creation / lookup and just return the QuerySet result
            return self.pages_for_display
        return super().get_children_for_page(page)
1135390
def extract_stations(page):
    '''
    '''
    stations = [_(station.value) for station in page('.stateName')]
    return {
        'terminal': {
            stations[0]: list(reversed(stations)),
            stations[-1]: stations
        },
        'stations': stations
    }
182328
function Page(page) {
  if (!page) page = {};
  for (var key in page) this[key] = page[key];
  if (!this.hasOwnProperty('idx')) this.idx = 0;
  if (!this.hasOwnProperty('total')) this.total = 1;
  if (!this.hasOwnProperty('current')) {
    this.current = this.total;
  }
}
1325356
def attributes(self):
        
        if not self._attribute_pages:
            self.fetch_attributes()
        result = {}
        for page in self._attribute_pages.values():
            result.update(page.attributes)
        return result
784021
def _get_page_elements(self):
        
        page_elements = []
        for attribute, value in list(self.__dict__.items()) + list(self.__class__.__dict__.items()):
            if attribute != 'parent' and isinstance(value, CommonObject):
                page_elements.append(value)
        return page_elements
163588
def extract(query_dict, prefix=""):
    

    strs = ['order_by']
    ints = ['per_page', 'page']

    extracted = { }

    for key in (strs + ints):
        if (prefix + key) in query_dict:
            val = query_dict.get(prefix + key)

            extracted[key] = (val
                if not key in ints
                else int(val))

    return extracted
849825
def get_departures(self, station):
        
        url = 'http://webservices.ns.nl/ns-api-avt?station=' + station

        raw_departures = self._request('GET', url)
        return self.parse_departures(raw_departures)
1264583
def visit_page(self, page):
    

    url = urljoin(django_url(self), page)
    self.given('I visit "%s"' % url)
831193
public static Page<Computer> page(int page, int pageSize, String sortBy, String order, String filter) {
        return 
            find.where()
                .ilike("name", "%" + filter + "%")
                .orderBy(sortBy + " " + order)
                .fetch("company")
                .findPagingList(pageSize)
                .getPage(page);
    }
1358690
def handle_json_GET_routepatterns(self, params):
    """"""
    schedule = self.server.schedule
    route = schedule.GetRoute(params.get('route', None))
    if not route:
      self.send_error(404)
      return
    time = int(params.get('time', 0))
    date = params.get('date', "")
    sample_size = 3  # For each pattern return the start time for this many trips

    pattern_id_trip_dict = route.GetPatternIdTripDict()
    patterns = []

    for pattern_id, trips in pattern_id_trip_dict.items():
      time_stops = trips[0].GetTimeStops()
      if not time_stops:
        continue
      has_non_zero_trip_type = False;

      # Iterating over a copy so we can remove from trips inside the loop
      trips_with_service = []
      for trip in trips:
        service_id = trip.service_id
        service_period = schedule.GetServicePeriod(service_id)

        if date and not service_period.IsActiveOn(date):
          continue
        trips_with_service.append(trip)

        if trip['trip_type'] and trip['trip_type'] != '0':
          has_non_zero_trip_type = True

      # We're only interested in the trips that do run on the specified date
      trips = trips_with_service

      name = u'%s to %s, %d stops' % (time_stops[0][2].stop_name, time_stops[-1][2].stop_name, len(time_stops))
      transitfeed.SortListOfTripByTime(trips)

      num_trips = len(trips)
      if num_trips <= sample_size:
        start_sample_index = 0
        num_after_sample = 0
      else:
        # Will return sample_size trips that start after the 'time' param.

        # Linear search because I couldn't find a built-in way to do a binary
        # search with a custom key.
        start_sample_index = len(trips)
        for i, trip in enumerate(trips):
          if trip.GetStartTime() >= time:
            start_sample_index = i
            break

        num_after_sample = num_trips - (start_sample_index + sample_size)
        if num_after_sample < 0:
          # Less than sample_size trips start after 'time' so return all the
          # last sample_size trips.
          num_after_sample = 0
          start_sample_index = num_trips - sample_size

      sample = []
      for t in trips[start_sample_index:start_sample_index + sample_size]:
        sample.append( (t.GetStartTime(), t.trip_id) )

      patterns.append((name, pattern_id, start_sample_index, sample,
                       num_after_sample, (0,1)[has_non_zero_trip_type]))

    patterns.sort()
    return patterns