@@ -174,12 +174,28 @@ def collect_stats(self):
174174 """Collect all statistics"""
175175 print ("🔍 Collecting repository statistics...\n " )
176176
177+ # Try to load previous stats for fallback
178+ previous_github_stats = {}
179+ if self .stats_file .exists ():
180+ try :
181+ with open (self .stats_file , 'r' ) as f :
182+ previous_data = json .load (f )
183+ previous_github_stats = previous_data .get ('github' , {})
184+ except :
185+ pass
186+
177187 stats = {
178188 "timestamp" : datetime .now (UTC ).strftime ('%Y-%m-%dT%H:%M:%S.%fZ' ),
179189 "local" : self .get_local_git_stats (),
180190 "github" : self .get_github_stats ()
181191 }
182192
193+ # If GitHub stats are empty but we have previous stats, preserve them
194+ if not stats ["github" ] and previous_github_stats :
195+ print ("ℹ️ Using cached GitHub stats from previous successful fetch" )
196+ stats ["github" ] = previous_github_stats
197+ stats ["github_cached" ] = True
198+
183199 return stats
184200
185201 def save_stats (self , stats ):
@@ -249,6 +265,8 @@ def display_stats(self, stats):
249265 # GitHub stats
250266 if stats .get ("github" ):
251267 print ("\n 🌐 GITHUB STATISTICS:" )
268+ if stats .get ("github_cached" ):
269+ print (" ℹ️ (Using cached data from previous successful fetch)" )
252270 print ("-" * 80 )
253271 gh = stats ["github" ]
254272 print (f" ⭐ Stars: { gh .get ('stars' , 'N/A' )} " )
@@ -274,7 +292,12 @@ def generate_stats_markdown(self, stats):
274292 md = f"""# Repository Statistics - Real-Time
275293
276294**Last Updated:** { stats ['timestamp' ]}
277-
295+ """
296+
297+ if stats .get ("github_cached" ):
298+ md += "\n > ℹ️ **Note:** GitHub metrics below are cached from previous successful fetch (current API call failed)\n "
299+
300+ md += """
278301## 📊 Current Statistics
279302
280303"""
0 commit comments