66
77import datetime
88import os
9+ import requests
910import time
11+ import traceback
1012
1113CI = os .environ .get ("CI" , None )
1214INVALIDATE_HOURS = int (os .environ .get ("INVALIDATE_HOURS" , "24" ))
15+ SCARF_TOKEN = os .environ .get ("SCARF_TOKEN" , None )
1316
1417
1518def get_tags (readme_vars ):
@@ -33,7 +36,7 @@ def get_architectures(readme_vars):
3336
3437def get_changelog (readme_vars ):
3538 if "changelogs" not in readme_vars :
36- return None
39+ return None , None
3740 changelog = []
3841 for item in readme_vars ["changelogs" ][0 :3 ]:
3942 changelog .append (Changelog (date = item ["date" ][0 :- 1 ], desc = item ["desc" ]))
@@ -138,7 +141,23 @@ def get_mac_address(readme_vars):
138141 hostname = readme_vars .get ("param_mac_address" , False )
139142 return MacAddress (mac_address = hostname , desc = readme_vars .get ("param_mac_address_desc" , "" ), optional = optional )
140143
141- def get_image (repo ):
144+ def get_monthly_pulls ():
145+ pulls_map = {}
146+ try :
147+ response = requests .get ("https://api.scarf.sh/v2/packages/linuxserver-ci/overview?per_page=1000" , headers = {"Authorization" : f"Bearer { SCARF_TOKEN } " })
148+ results = response .json ()["results" ]
149+ for result in results :
150+ name = result ["package" ]["name" ].replace ("linuxserver/" , "" )
151+ if "total_installs" not in result :
152+ continue
153+ monthly_pulls = result ["total_installs" ]
154+ pulls_map [name ] = monthly_pulls
155+ except Exception :
156+ print (traceback .format_exc ())
157+ raise
158+ return pulls_map
159+
160+ def get_image (repo , pulls_map ):
142161 print (f"Processing { repo .name } " )
143162 if not repo .name .startswith ("docker-" ) or repo .name .startswith ("docker-baseimage-" ):
144163 return None
@@ -176,7 +195,6 @@ def get_image(repo):
176195 name = project_name ,
177196 initial_date = initial_date ,
178197 github_url = repo .html_url ,
179- stars = repo .stargazers_count ,
180198 project_url = readme_vars .get ("project_url" , None ),
181199 project_logo = readme_vars .get ("project_logo" , None ),
182200 description = get_description (readme_vars ),
@@ -185,6 +203,8 @@ def get_image(repo):
185203 category = categories ,
186204 stable = stable ,
187205 deprecated = deprecated ,
206+ stars = repo .stargazers_count ,
207+ monthly_pulls = pulls_map .get (project_name , None ),
188208 tags = tags ,
189209 architectures = get_architectures (readme_vars ),
190210 changelog = changelog ,
@@ -198,16 +218,17 @@ def update_images():
198218 print (f"{ datetime .datetime .now ()} - skipped - already updated" )
199219 return
200220 print (f"{ datetime .datetime .now ()} - updating images" )
221+ pulls_map = get_monthly_pulls ()
201222 images = []
202223 repos = gh .get_repos ()
203224 for repo in sorted (repos , key = lambda repo : repo .name ):
204- image = get_image (repo )
225+ image = get_image (repo , pulls_map )
205226 if not image :
206227 continue
207228 images .append (image )
208229
209230 data = ImagesData (repositories = Repository (linuxserver = images ))
210- last_updated = datetime .datetime .now (datetime .timezone .utc ).isoformat (' ' , ' seconds' )
231+ last_updated = datetime .datetime .now (datetime .timezone .utc ).isoformat (" " , " seconds" )
211232 response = ImagesResponse (status = "OK" , last_updated = last_updated , data = data )
212233 new_state = response .model_dump_json (exclude_none = True )
213234 kv .set_value ("images" , new_state , IMAGES_SCHEMA_VERSION )
0 commit comments