Skip to content

Commit

Permalink
Cache PyPI responses for one hour
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Sep 5, 2024
1 parent fb1d09e commit c152fc1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.pyc
node_modules
requests-cache.sqlite
results.json
top-pypi-packages.json
wheel.svg
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pre-commit==3.3.2
pytz==2023.3.post1
requests==2.31.0
pre-commit==3.8.0
pytz==2024.1
requests==2.32.3
requests-cache==1.2.1
7 changes: 4 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import json
import pytz
import requests
import requests_cache


BASE_URL = "https://pypi.org/pypi"
Expand All @@ -18,7 +18,8 @@
"sklearn",
}

SESSION = requests.Session()
# Keep responses for one hour
SESSION = requests_cache.CachedSession("requests-cache", expire_after=60 * 60)


def get_json_url(package_name):
Expand Down Expand Up @@ -51,7 +52,7 @@ def annotate_wheels(packages):
else:
package["css_class"] = "default"
package["icon"] = "\u2717" # Ballot X
package["title"] = "This package has no wheel archives uploaded " "(yet!)."
package["title"] = "This package has no wheel archives uploaded (yet!)."


def get_top_packages():
Expand Down

0 comments on commit c152fc1

Please sign in to comment.