Created
August 2, 2017 04:21
-
-
Save sirpengi/d6d74c34e008316028e6c7bf4319b809 to your computer and use it in GitHub Desktop.
cached requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
from os import stat, unlink | |
import requests | |
import vcr | |
CFILE = "blah.cassette" | |
TTL = timedelta(minutes=15) | |
try: | |
cstat = stat(CFILE) | |
except OSError: | |
pass | |
else: | |
if cstat and datetime.fromtimestamp(cstat.st_mtime) < (datetime.now() - TTL): | |
unlink(CFILE) | |
with vcr.use_cassette(CFILE): | |
r = requests.get("http://httpbin.org/get") | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment