File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 26
26
"mbussonn" : "Carreau" ,
27
27
}
28
28
29
+ import diskcache
30
+ from datetime import datetime
31
+
32
+ CACHE_DIR = f"github_cache-all_repos-{ datetime .now ().strftime ('%Y%m%d' )} "
33
+ cache = diskcache .Cache (CACHE_DIR )
34
+
29
35
30
36
def get_packages (url ):
31
37
# Send a GET request to the webpage with a custom user agent
@@ -125,14 +131,18 @@ async def get_package_maintainers(package: str) -> list[str]:
125
131
The json does not have the right information, so we need to scrape the page.
126
132
"""
127
133
url = f"https://pypi.org/project/{ package } /"
134
+ if package in cache :
135
+ return cache [package ]
128
136
response = await asks .get (url )
129
137
if response .status_code == 200 :
130
138
html = response .text
131
139
soup = BeautifulSoup (html , "html.parser" )
132
140
maintainers = soup .find_all ("span" , class_ = "sidebar-section__maintainer" )
133
141
if not maintainers :
134
142
return set (["unknown (blocked by fastly?)" ])
135
- return set (a .text .strip () for a in maintainers )
143
+ res = set (a .text .strip () for a in maintainers )
144
+ cache [package ] = res
145
+ return res
136
146
return set (["unknown (status code: " + str (response .status_code ) + ")" ])
137
147
138
148
You can’t perform that action at this time.
0 commit comments