Skip to content

Instantly share code, notes, and snippets.

@sirpengi sirpengi/blah.py

Created Aug 2, 2017
Embed
What would you like to do?
cached requests
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
You can’t perform that action at this time.