How to use the cachecontrol.heuristics.ExpiresAfter function in CacheControl

To help you get started, we’ve selected a few CacheControl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionrock / cachecontrol / tests / test_expires_heuristics.py View on Github external
def setup(self):
        self.sess = Session()
        self.cache_sess = CacheControl(self.sess, heuristic=ExpiresAfter(days=1))
github NikhilNarayana / FRC-YouTube-Uploader / frcuploader / utils.py View on Github external
import requests
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload

from . import consts
from .youtube import upload, RETRIABLE_EXCEPTIONS, RETRIABLE_STATUS_CODES

from cachecontrol import CacheControl
from cachecontrol.heuristics import ExpiresAfter

app_id = {'X-TBA-App-Id': ""}
trusted_auth = {'X-TBA-Auth-Id': "", 'X-TBA-Auth-Sig': ""}

s = requests.Session()
s = CacheControl(s, heuristic=ExpiresAfter(minutes=1))
s.headers.update(app_id)


"""Utility Functions"""


def convert_bytes(num):
    for x in consts.sizes:
        if num < 1024.0:
            return "%3.1f %s" % (num, x)
        num /= 1024.0


def file_size(path):
    file_info = os.stat(path)
    return convert_bytes(file_info.st_size)
github NikhilNarayana / FRC-YouTube-Uploader / tbaAPI.py View on Github external
# Written by Wes Jordan and found here: Python TBA API Layer (https://github.com/Thing342/pyTBA)
import simplejson as json
import requests
import hashlib
import re
import time

from cachecontrol import CacheControl
from cachecontrol.heuristics import ExpiresAfter

app_id = {'X-TBA-App-Id': ""}
trusted_auth = {'X-TBA-Auth-Id': "", 'X-TBA-Auth-Sig': ""}

s = requests.Session()
s = CacheControl(s, heuristic=ExpiresAfter(minutes=1))
s.headers.update(app_id)


class Event:
	def __init__(self, info, teams, matches, awards, rankings):
		self.key = info['key']
		self.info = info
		self.teams = list(filter(lambda team: len(list(filter(
			lambda match: team['key'] in match['alliances']['red']['teams'] or team['key'] in
																			   match['alliances']['blue']['teams'],
			matches))) > 0, teams))
		self.matches = sorted(matches, key=match_sort_key)
		self.awards = awards
		self.rankings = rankings

	def get_match(self, match_key):
github NikhilNarayana / FRC-YouTube-Uploader / frcuploader / youtubeup.py View on Github external
import tbapy
import requests
import json
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload

from .consts import *

from cachecontrol import CacheControl
from cachecontrol.heuristics import ExpiresAfter

app_id = {'X-TBA-App-Id': ""}
trusted_auth = {'X-TBA-Auth-Id': "", 'X-TBA-Auth-Sig': ""}

s = requests.Session()
s = CacheControl(s, heuristic=ExpiresAfter(minutes=1))
s.headers.update(app_id)
"""Utility Functions"""


def convert_bytes(num):
    for x in sizes:
        if num < 1024.0:
            return "%3.1f %s" % (num, x)
        num /= 1024.0


def file_size(path):
    file_info = os.stat(path)
    return convert_bytes(file_info.st_size)
github OnroerendErfgoed / atramhasis / atramhasis / skos / __init__.py View on Github external
'uri': dataseturigenerator.generate(id='soorten'),
                    'publisher': ['https://id.erfgoed.net/actoren/501'],
                    'created': [date(2011, 5, 23)],
                    'language': ['nl-BE', 'la'],
                    'license': LICENSES
                },
                'atramhasis.force_display_label_language': 'la'
            },
            request.db,
            uri_generator=UriPatternGenerator('https://id.erfgoed.net/thesauri/soorten/%s')
        )

        # use 'subject': ['external'] for read only external providers
        # (only available in REST service)

        getty_session = CacheControl(requests.Session(), heuristic=ExpiresAfter(weeks=1))

        aat = AATProvider(
            {'id': 'AAT', 'subject': ['external']},
            session=getty_session
        )

        tgn = TGNProvider(
            {'id': 'TGN', 'subject': ['external']},
            session=getty_session
        )

        registry.register_provider(trees)
        registry.register_provider(geo)
        registry.register_provider(styles)
        registry.register_provider(materials)
        registry.register_provider(eventtypes)