def iiif_info(msid, filename): context = { 'msid': msid, 'iiif_filename': filename, 'iiif_info_url': iiif_info_url(msid, filename) } try: url = iiif_info_url(msid, filename) LOG.info("Loading IIIF info URL: %s", url) resp = utils.requests_get(url) except requests.ConnectionError: LOG.debug("IIIF request failed", extra=context) return {} context['status-code'] = resp.status_code if resp.status_code == 404: LOG.debug("IIIF image not found", extra=context) return {} elif resp.status_code != 200: msg = "unhandled status code from IIIF" LOG.warn(msg, extra=context) raise ValueError(msg + ": %s" % resp.status_code) try: info_data = utils.sortdict(resp.json()) return info_data except BaseException: # clear cache, we don't want bad data hanging around clear_cache(msid, filename) raise
def metadata(msid): # 2018-10-19: it's now possible for glencoe to be queried about an article before media # has been deposited by elife-bot. only successful responses will be cached url = glencoe_url(msid) resp = utils.requests_get(url) context = {'msid': msid, 'glencoe-url': url, 'status-code': resp.status_code} if resp.status_code != 200: clear_cache(msid) if resp.status_code == 404: LOG.debug("article has no videos", extra=context) return {} msg = "unhandled status code from Glencoe" context["response"] = resp # TODO: object handling? LOG.error(msg, extra=context) raise ValueError("%s: %s" % (msg, resp.status_code)) try: gc_data = sortdict(resp.json()) validate_gc_data(gc_data) return gc_data except AssertionError: # clear cache, we don't want bad data hanging around clear_cache(msid) raise
def _get_price(self, row): # 获取每列车不同席别的票价,返回一个列表 params = self._build_params(row) r = requests_get(PRICE_QUERY_URL, params=params, verify=False) rows = {} try: rows = r.json()['data'] # 得到json查询结果 except KeyError: rows = {} except TypeError: pass except ValueError: rows = {} return rows
def metadata(msid): # 2018-10-19: it's now possible for glencoe to be queried about an article before media # has been deposited by elife-bot. only successful responses will be cached url = glencoe_url(msid) if conf.REQUESTS_CACHING and conf.GLENCOE_REQUESTS_CACHING: resp = utils.requests_get(url) else: with requests_cache.disabled(): resp = utils.requests_get(url) context = { 'msid': msid, 'glencoe-url': url, 'status-code': resp.status_code } if resp.status_code != 200: clear_cache(msid) if resp.status_code == 404: LOG.debug("article has no videos", extra=context) return {} msg = "unhandled status code from Glencoe" context["response"] = resp # TODO: object handling? LOG.error(msg, extra=context) raise ValueError("%s: %s" % (msg, resp.status_code)) try: gc_data = sortdict(resp.json()) validate_gc_data(gc_data) return gc_data except AssertionError: # clear cache, we don't want bad data hanging around clear_cache(msid) raise
def query(self): params = self._build_params() r = requests_get(QUERY_URL, params=params, verify=False) rows = [] try: rows = r.json()['data']['datas'] # 得到json查询结果 except KeyError: rows = [] except TypeError: exit_after_echo(NO_RESPONSE) except ValueError: rows = [] query_date = self._valid_date return TrainsCollection(rows, self.opts, query_date, self.from_station, self.to_station)
def metadata(msid): resp = utils.requests_get(glencoe_url(msid)) context = {'msid': msid, 'status-code': resp.status_code} if resp.status_code == 404: LOG.debug("article has no videos", extra=context) return {} elif resp.status_code != 200: msg = "unhandled status code from Glencoe" LOG.warn(msg, extra=context) raise ValueError(msg + ": %s" % resp.status_code) try: gc_data = resp.json() validate_gc_data(gc_data) return gc_data except AssertionError: # clear cache, we don't want bad data hanging around clear_cache(msid) raise
def get_statistics(self): url = "{}/v2/{}".format(self.BASE_URL, "all") response = requests_get(url) return json.loads(response.text)
def get_country_historical(self, country="Bangladesh"): url = "{}/v2/{}/{}".format(self.BASE_URL, "historical", country) response = requests_get(url) return json.loads(response.text)
def get_countries_historical(self): url = "{}/v2/{}".format(self.BASE_URL, "historical") response = requests_get(url) return json.loads(response.text)