Last active
February 16, 2023 21:55
-
-
Save caseydm/80b6e3f5961f683bb8edb8636c098579 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 grequests | |
def test_rate_limit_no_key(): | |
# test url 20 times at once | |
# 10 of the responses are 429, rate limited | |
urls = [] | |
for i in range(20): | |
urls.append( | |
"https://api.openalex.org/works?filter=doi:10.1016/j.jfca.2023.105165") | |
rs = (grequests.get(u) for u in urls) | |
print(grequests.map(rs)) | |
def test_rate_limit_with_key(): | |
# test 101 times at once | |
# 1 response is 429, rate limited | |
urls = [] | |
for i in range(101): | |
urls.append("https://api.openalex.org/works?filter=doi:10.1016/j.jfca.2023.105165&api_key=my_api_key") | |
rs = (grequests.get(u) for u in urls) | |
print(grequests.map(rs)) | |
if __name__ == "__main__": | |
print("no key") | |
test_rate_limit_no_key() | |
print("with key") | |
test_rate_limit_with_key() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment