File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828WEEK_SECONDS = 7 * 24 * 60 * 60 # for trending feature
2929
3030def load_previous_users (path : str = "./docs/users.json" ) -> Dict [str , Dict [str , Any ]]:
31- """
32- trending feature -> load previous users.json and index by login
33-
34- to calcute the follower growth
31+ """Load previous user data from a JSON file and index it by login.
32+ This is used to calculate follower growth for the trending feature.
3533 """
3634 if not os .path .exists (path ):
3735 return {}
3836 try :
3937 with open (path , "r" , encoding = "utf-8" ) as f :
4038 users = json .load (f )
41- return {u .get ("login" ): u for u in users if "login" in u }
42- except Exception :
39+ if not isinstance (users , list ):
40+ logger .warning (f"Data in { path } is not a list, returning empty dict." )
41+ return {}
42+ return {u ["login" ]: u for u in users if isinstance (u , dict ) and "login" in u }
43+ except (IOError , json .JSONDecodeError ) as e :
44+ logger .warning (f"Failed to load or parse previous users from { path } : { e } " )
4345 return {}
4446
4547
You can’t perform that action at this time.
0 commit comments