Fetch from FCPS' emergency announcement page.

    URL defined in settings.FCPS_EMERGENCY_PAGE

    Request timeout defined in settings.FCPS_EMERGENCY_TIMEOUT
199174
def check_emerg():
    
    status = True
    message = None
    if settings.EMERGENCY_MESSAGE:
        return True, settings.EMERGENCY_MESSAGE
    if not settings.FCPS_EMERGENCY_PAGE:
        return None, None

    timeout = settings.FCPS_EMERGENCY_TIMEOUT

    r = requests.get("{}?{}".format(settings.FCPS_EMERGENCY_PAGE, int(time.time() // 60)), timeout=timeout)
    res = r.text
    if not res or len(res) < 1:
        status = False

    # Keep this list up to date with whatever wording FCPS decides to use each time...
    bad_strings = [
        "There are no emergency announcements at this time", "There are no emergency messages at this time",
        "There are no emeregency annoncements at this time", "There are no major announcements at this time.",
        "There are no major emergency announcements at this time.", "There are no emergencies at this time."
    ]
    for b in bad_strings:
        if b in res:
            status = False
            break

    # emerg_split = '<p><a href="https://youtu.be/jo_8QFIEf64'
    # message = res.split(emerg_split)[0]
    soup = BeautifulSoup(res, "html.parser")
    if soup.title:
        title = soup.title.text
        body = ""
        for cd in soup.findAll(text=True):
            if isinstance(cd, CData):
                body += cd
        message = "<h3>{}: </h3>{}".format(title, body)
        message = message.strip()
    else:
        status = False

    return status, message
348963
def fetch(self, pageNum, itemsPerPage):
        
        return self.get_all_alerts(self.status, pageNum, itemsPerPage)
377590
def get_incidents(self, offset=0, limit=None, include_resolved=False, **kwargs):
        
        resp = self._get(
            self._u(self._INCIDENT_ENDPOINT_SUFFIX),
            params={
                'offset': offset,
                'limit': limit,
                'include_resolved': str(include_resolved).lower(),
            },
            **kwargs)

        resp.raise_for_status()
        return resp.json()
806315
async def fetch(self, url, method='GET', headers=None, body=None):
        """"""
        request_headers = self.prepare_request_headers(headers)
        url = self.proxy + url

        if self.verbose:
            print("\nRequest:", method, url, headers, body)
        self.logger.debug("%s %s, Request: %s %s", method, url, headers, body)

        encoded_body = body.encode() if body else None
        session_method = getattr(self.session, method.lower())

        response = None
        http_response = None
        json_response = None
        try:
            async with session_method(yarl.URL(url, encoded=True),
                                      data=encoded_body,
                                      headers=request_headers,
                                      timeout=(self.timeout / 1000),
                                      proxy=self.aiohttp_proxy) as response:
                http_response = await response.text()
                json_response = self.parse_json(http_response) if self.is_json_encoded_object(http_response) else None
                headers = response.headers
                if self.enableLastHttpResponse:
                    self.last_http_response = http_response
                if self.enableLastResponseHeaders:
                    self.last_response_headers = headers
                if self.enableLastJsonResponse:
                    self.last_json_response = json_response
                if self.verbose:
                    print("\nResponse:", method, url, response.status, headers, http_response)
                self.logger.debug("%s %s, Response: %s %s %s", method, url, response.status, headers, http_response)

        except socket.gaierror as e:
            self.raise_error(ExchangeNotAvailable, url, method, e, None)

        except concurrent.futures._base.TimeoutError as e:
            self.raise_error(RequestTimeout, method, url, e, None)

        except aiohttp.client_exceptions.ClientConnectionError as e:
            self.raise_error(ExchangeNotAvailable, url, method, e, None)

        except aiohttp.client_exceptions.ClientError as e:  # base exception class
            self.raise_error(ExchangeError, url, method, e, None)

        self.handle_errors(response.status, response.reason, url, method, headers, http_response, json_response)
        self.handle_rest_errors(None, response.status, http_response, url, method)
        self.handle_rest_response(http_response, json_response, url, method, headers, body)
        if json_response is not None:
            return json_response
        return http_response
577273
def fetch(self, *args, **kwargs):
        
        response = client.get('/tables/Notifications/{0}'.format(self.id))
        self._update_data(response.json())
1031007
def fetch(self, station: str) -> str:
        
        valid_station(station)
        try:
            resp = getattr(requests, self.method.lower())(self.url.format(self.rtype, station))
            if resp.status_code != 200:
                raise SourceError(f'{self.__class__.__name__} server returned {resp.status_code}')
        except requests.exceptions.ConnectionError:
            raise ConnectionError(f'Unable to connect to {self.__class__.__name__} server')
        report = self._extract(resp.text, station)
        # This split join replaces all *whitespace elements with a single space
        return ' '.join(report.split())
228565
def fetch(self, url, method='GET', headers=None, body=None):
        """"""
        request_headers = self.prepare_request_headers(headers)
        url = self.proxy + url

        if self.verbose:
            print("\nRequest:", method, url, request_headers, body)
        self.logger.debug("%s %s, Request: %s %s", method, url, request_headers, body)

        if body:
            body = body.encode()

        self.session.cookies.clear()

        response = None
        http_response = None
        json_response = None
        try:
            response = self.session.request(
                method,
                url,
                data=body,
                headers=request_headers,
                timeout=int(self.timeout / 1000),
                proxies=self.proxies
            )
            http_response = response.text
            json_response = self.parse_json(http_response) if self.is_json_encoded_object(http_response) else None
            headers = response.headers
            # FIXME remove last_x_responses from subclasses
            if self.enableLastHttpResponse:
                self.last_http_response = http_response
            if self.enableLastJsonResponse:
                self.last_json_response = json_response
            if self.enableLastResponseHeaders:
                self.last_response_headers = headers
            if self.verbose:
                print("\nResponse:", method, url, response.status_code, headers, http_response)
            self.logger.debug("%s %s, Response: %s %s %s", method, url, response.status_code, headers, http_response)
            response.raise_for_status()

        except Timeout as e:
            self.raise_error(RequestTimeout, method, url, e)

        except TooManyRedirects as e:
            self.raise_error(ExchangeError, url, method, e)

        except SSLError as e:
            self.raise_error(ExchangeError, url, method, e)

        except HTTPError as e:
            self.handle_errors(response.status_code, response.reason, url, method, headers, http_response, json_response)
            self.handle_rest_errors(e, response.status_code, http_response, url, method)
            self.raise_error(ExchangeError, url, method, e, http_response)

        except RequestException as e:  # base exception class
            error_string = str(e)
            if ('ECONNRESET' in error_string) or ('Connection aborted.' in error_string):
                self.raise_error(NetworkError, url, method, e)
            else:
                self.raise_error(ExchangeError, url, method, e)

        self.handle_errors(response.status_code, response.reason, url, method, headers, http_response, json_response)
        self.handle_rest_response(http_response, json_response, url, method, headers, body)
        if json_response is not None:
            return json_response
        return http_response
300807
def _fetch(url, ssl_verify = True):
    
    req = Request(url)
    if ssl_verify:
        page = urlopen(req)
    else:
        ctx = ssl.create_default_context()
        ctx.check_hostname = False
        ctx.verify_mode = ssl.CERT_NONE

        page = urlopen(req, context=ctx)
    content = page.read().decode('utf-8')
    page.close()
    return content
363180
def fetch(cls, id, incident=None, endpoint=None, *args, **kwargs):
        """"""
        if incident is None and endpoint is None:
            raise InvalidArguments(incident, endpoint)

        if endpoint is None:
            iid = incident['id'] if isinstance(incident, Entity) else incident
            endpoint = 'incidents/{0}/alerts'.format(iid)

        return getattr(Entity, 'fetch').__func__(cls, id, endpoint=endpoint,
                                                 *args, **kwargs)
278551
def _fetch(self, uri, sub_domain=False):
        
        url = self._build_request_url(uri, sub_domain=sub_domain)

        try:
            res = self.request_handler.send("HEAD", url=url, allow_redirects=self.follow_redirects)
            if res.status_code not in self.ignored_error_codes:
                self._log_response(res.status_code, url, res.headers)
        except (AttributeError, RequestHandlerException):
            # res is None or another error occurred
            pass
81915
def get(self, request=None, timeout=1.0):
        
        if request is None:
            request = nfc.ndef.Message(nfc.ndef.Record())

        if not isinstance(request, nfc.ndef.Message):
            raise TypeError("request type must be nfc.ndef.Message")

        response_data = self._get(request, timeout)

        if response_data is not None:
            try:
                response = nfc.ndef.Message(response_data)
            except Exception as error:
                log.error(repr(error))
            else:
                return response
1192277
def search_fetch_force(request, id, redirect_to):
    """"""
    search = Search.objects.get(id=id)
    search.fetch(force=True)
    msg = _("Fetched tweets for %s" % search.criteria)
    messages.success(request, msg, fail_silently=True)
    return HttpResponseRedirect(redirect_to)
882442
function download(url, dest, cb) {
  var reportError = function(err) {
    var timeoutMessge;

    if (err.code === 'ETIMEDOUT') {
      if (err.connect === true) {
        // timeout is hit while your client is attempting to establish a connection to a remote machine
        timeoutMessge = 'Timed out attemping to establish a remote connection';
      } else {
        timeoutMessge = 'Timed out whilst downloading the prebuilt binary';
        // occurs any time the server is too slow to send back a part of the response
      }

    }
    cb(['Cannot download "', url, '": ', eol, eol,
      typeof err.message === 'string' ? err.message : err, eol, eol,
      timeoutMessge ? timeoutMessge + eol + eol : timeoutMessge,
      'Hint: If github.com is not accessible in your location', eol,
      '      try setting a proxy via HTTP_PROXY, e.g. ', eol, eol,
      '      export HTTP_PROXY=http://example.com:1234',eol, eol,
      'or configure npm proxy via', eol, eol,
      '      npm config set proxy http://example.com:8080'].join(''));
  };

  var successful = function(response) {
    return response.statusCode >= 200 && response.statusCode < 300;
  };

  console.log('Downloading binary from', url);

  try {
    request(url, downloadOptions(), function(err, response, buffer) {
      if (err) {
        reportError(err);
      } else if (!successful(response)) {
        reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
      } else {
        console.log('Download complete');

        if (successful(response)) {
          fs.createWriteStream(dest)
            .on('error', cb)
            .end(buffer, cb);
        } else {
          cb();
        }
      }
    })
    .on('response', function(response) {
      var length = parseInt(response.headers['content-length'], 10);
      var progress = log.newItem('', length);

      // The `progress` is true by default. However if it has not
      // been explicitly set it's `undefined` which is considered
      // as far as npm is concerned.
      if (process.env.npm_config_progress === 'true') {
        log.enableProgress();

        response.on('data', function(chunk) {
          progress.completeWork(chunk.length);
        })
        .on('end', progress.finish);
      }
    });
  } catch (err) {
    cb(err);
  }
}
1036775
def _request_get_helper(self, url, params=None):
        ''''''
        if not isinstance(params, dict):
            params = dict()

        if self.api_key:
            params['api_key'] = self.api_key
        return requests.get(url, params=params, timeout=60)
493715
function(callback){
    var options = this.options,
        cache = this.options.cache,
        logger =  this.options.logger;


    if(this.url){
      logger.log('fetch page: ' + this.url);

      // if there is a cache and it holds the url
      if(cache &&cache.has(this.url)){
        // http status - content located elsewhere, retrieve from there
        this.statusCode = 305;
        this.requestTime = 0;
        this.html = cache.get(this.url);
        logger.log('fetched html from cache: ' + this.url);

        this.parse(function(){
          callback(this);
        })

      // if not get the html from the url  
      }else{

        this.startedRequest = new Date();
        var self = this;

        var requestObj = {
          uri: this.url,
          headers: options.httpHeaders
        }

        request(requestObj, function(requestErrors, response, body){
          if(!requestErrors && response.statusCode === 200){

            self.endedRequest = new Date();
            self.requestTime = self.endedRequest.getTime() - self.startedRequest.getTime();
            logger.log('fetched html from page: ' 
              + self.requestTime + 'ms - ' + self.url);
            
            self.statusCode = response.statusCode;
            self.html = body;

            if(cache){
              cache.set(self.url, body);
            }

            self.parse(function(){
              self.status = "fetched";
              callback(self);
            })

          }else{
            logger.warn('error requesting page: ' + self.url);
            self.error = 'error requesting page: ' + self.url;
            self.status = "errored";
            callback();
          }
        });


      }
    }else{
      logger.warn('no url given');
      this.error = 'no url given';
      this.status = "errored";
      callback();
    }
  }
310141
def http_error_handler(f):
    

    def hrefs_to_resources(hrefs):
        for href in hrefs.replace(',', '').split():
            type, uuid = href.split('/')[-2:]
            yield Resource(type, uuid=uuid)

    def hrefs_list_to_resources(hrefs_list):
        for href in eval(hrefs_list):
            type, uuid = href.split('/')[-2:]
            yield Resource(type, uuid=uuid)

    @wraps(f)
    def wrapper(self, *args, **kwargs):
        try:
            return f(self, *args, **kwargs)
        except HttpError as e:
            if e.http_status == 404:
                # remove previously created resource
                # from the cache
                self.emit('deleted', self)
                if isinstance(self, Resource):
                    raise ResourceNotFound(resource=self)
                elif isinstance(self, Collection):
                    raise CollectionNotFound(collection=self)
            elif e.http_status == 409:
                # contrail 3.2
                matches = re.match(r'^Delete when children still present: (\[[^]]*\])', e.message)
                if matches:
                    raise ChildrenExists(
                        resources=list(hrefs_list_to_resources(matches.group(1))))
                matches = re.match(r'^Delete when resource still referred: (\[[^]]*\])', e.message)
                if matches:
                    raise BackRefsExists(
                        resources=list(hrefs_list_to_resources(matches.group(1))))
                # contrail 2.21
                matches = re.match(r'^Children (.*) still exist$', e.message)
                if matches:
                    raise ChildrenExists(
                        resources=list(hrefs_to_resources(matches.group(1))))
                matches = re.match(r'^Back-References from (.*) still exist$', e.message)
                if matches:
                    raise BackRefsExists(
                        resources=list(hrefs_to_resources(matches.group(1))))
            raise
    return wrapper
1181632
def request(self, **kwargs):
        

        self.prepare_request(**kwargs)
        refresh_count = 0

        while True:
            self.log_request()

            try:
                self.transport.request()
            except error.GrabError as ex:
                self.exception = ex
                self.reset_temporary_options()
                if self.config['log_dir']:
                    self.save_failed_dump()
                raise
            else:
                doc = self.process_request_result()

                if self.config['follow_location']:
                    if doc.code in (301, 302, 303, 307, 308):
                        if doc.headers.get('Location'):
                            refresh_count += 1
                            if refresh_count > self.config['redirect_limit']:
                                raise error.GrabTooManyRedirectsError()
                            else:
                                url = doc.headers.get('Location')
                                self.prepare_request(
                                    url=self.make_url_absolute(url),
                                    referer=None)
                                continue

                if self.config['follow_refresh']:
                    refresh_url = self.doc.get_meta_refresh_url()
                    if refresh_url is not None:
                        refresh_count += 1
                        if refresh_count > self.config['redirect_limit']:
                            raise error.GrabTooManyRedirectsError()
                        else:
                            self.prepare_request(
                                url=self.make_url_absolute(refresh_url),
                                referer=None)
                            continue
                return doc