readthedocsΒΆ
This is a slightly more advanced example, where we query readthedocs.io for articles.
from hoverpy import capture
import requests
import time
@capture("readthedocs.db", recordMode="once")
def getLinks(limit):
start = time.time()
sites = requests.get(
"http://readthedocs.org/api/v1/project/?limit=%d&offset=0&format=json" % int(limit))
objects = sites.json()['objects']
for link in ["http://readthedocs.org" + x['resource_uri'] for x in objects]:
response = requests.get(link)
print("url: %s, status code: %s" % (link, response.status_code))
print("Time taken: %f" % (time.time() - start))
getLinks(50)
python examples/readthedocs/readthedocs.py
The first time this command is invoked it takes Time taken: 7.658194
. The second time we run it, Time taken: 0.093647
. Please note this uses the recordMode="once"
which is legacy from Ruby’s VCR and Python’s VCR.py.