Created
September 19, 2018 08:52
-
-
Save fsschmitt/6e7cc9327a6999b93c51608e529d9400 to your computer and use it in GitHub Desktop.
Python's requests_cache library example
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
import time | |
import requests | |
import requests_cache | |
requests_cache.install_cache('tmp/demo_cache', expire_after=120) | |
start_time = time.time() | |
for i in range(10): | |
r = requests.get('http://httpbin.org/delay/1?index={}'.format(i)) | |
print("Request {}{}: {}".format(i+1," (from cache)" if r.from_cache else " (live)",r.text)) | |
print("--- %s seconds ---" % (time.time() - start_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment