import logging import requests_cache from cache_requests import install_cache_requests import conf, utils from utils import ensure, lmap, lfilter LOG = logging.getLogger(__name__) if conf.REQUESTS_CACHING: install_cache_requests() ''' glencoe_resp = { "media1": { "source_href": "https://static-movie-usa.glencoesoftware.com/source/10.7554/659/0f10378e095dde7aaf579af504c4bfdc6fb86550/elife-00569-media1.wmv", "doi": "10.7554/eLife.00569.019", "flv_href": "https://static-movie-usa.glencoesoftware.com/flv/10.7554/659/0f10378e095dde7aaf579af504c4bfdc6fb86550/elife-00569-media1.flv", "uuid": "55f163d5-f0d9-415b-8ae8-ec75ed83b026", "title": "", "video_id": "media1", "solo_href": "https://movie-usa.glencoesoftware.com/video/10.7554/eLife.00569/media1", "height": 480, "ogv_href": "https://static-movie-usa.glencoesoftware.com/ogv/10.7554/659/0f10378e095dde7aaf579af504c4bfdc6fb86550/elife-00569-media1.ogv", "width": 640, "href": "elife-00569-media1.wmv", "webm_href": "https://static-movie-usa.glencoesoftware.com/webm/10.7554/659/0f10378e095dde7aaf579af504c4bfdc6fb86550/elife-00569-media1.webm", "jpg_href": "https://static-movie-usa.glencoesoftware.com/jpg/10.7554/659/0f10378e095dde7aaf579af504c4bfdc6fb86550/elife-00569-media1.jpg", "duration": 54.487, "mp4_href": "https://static-movie-usa.glencoesoftware.com/mp4/10.7554/659/0f10378e095dde7aaf579af504c4bfdc6fb86550/elife-00569-media1.mp4", "legend": "",
import logging import requests import requests_cache from cache_requests import install_cache_requests import conf LOG = logging.getLogger(__name__) if conf.REQUESTS_CACHING: install_cache_requests() def clear_cache(url): conf.REQUESTS_CACHING and requests_cache.core.get_cache().delete_url(url) def url_exists(url, msid=None): context = {'msid': msid, 'url': url} try: resp = requests.head(url) except requests.ConnectionError: LOG.debug("CDN request failed", extra=context) return None context['status-code'] = resp.status_code if resp.status_code == 200: return url # non-200 response