bpyutils.request.get

Here are the examples of the python api bpyutils.request.get taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

0 Source : pubgrub.py
with MIT License
from achillesrasquinha

def populate_db():
    dt_now = dt.now()

    logger.info("Populating DB...")

    path_gzip = osp.join(PATH["CACHE"], "dependencies.json.gz")
    path_uzip = osp.join(PATH["CACHE"], "dependencies.json")

    refresh   = False

    if not osp.exists(path_gzip):
        refresh = True
    else:
        time_modified = dt.fromtimestamp( osp.getmtime(path_gzip) )
        cache_seconds = settings.get("cache_timeout")
        delta_seconds = (time_modified - dt_now).total_seconds()

        if delta_seconds > cache_seconds:
            refresh = True

    if refresh:
        logger.info("Fetching Dependency Graph...")

        response = req.get("https://github.com/achillesrasquinha/pipupgrade/blob/master/data/dependencies.json.gz?raw=true",
            stream = True)

        if response.ok:
            with open(path_gzip, "wb") as f:
                for content in response.iter_content(chunk_size = 1024):
                    f.write(content)
        else:
            response.raise_for_status()

        with gzip.open(path_gzip, "rb") as rf:
            with open(path_uzip, "wb") as wf:
                content = rf.read()
                wf.write(content)

_DEPENDENCIES = {}