@@ -44,28 +44,27 @@ def _extract_filename_from_url(url: str) -> str:
4444 return components [- 1 ] if components else 'resource'
4545
4646
47- def _load_test_resources (url_list : list [ str ]) -> dict [str , bytes ]:
47+ def _load_test_resources (url_dict : dict [ str , str ]) -> dict [str , bytes ]:
4848 """Load test resources from local files.
4949
5050 Args:
51- url_list: List of local file paths from scraper.get_urls()
51+ url_dict: Dict mapping resource key to local file path from scraper.get_urls()
5252
5353 Returns:
54- Dict mapping URL to bytes
54+ Dict mapping resource key to bytes
5555 """
5656 resources = {}
5757
58- for url in url_list :
58+ for key , url in url_dict . items () :
5959 # Strip query parameters (e.g., ?public=true) from file path
60- # but keep original URL as key in resources dict
6160 base_path = url .split ('?' )[0 ] if '?' in url else url
6261
6362 # Try common extensions
6463 for ext in ['' , '.json' , '.html' , '.txt' ]:
6564 filepath = f'{ base_path } { ext } '
6665 if os .path .exists (filepath ):
6766 with open (filepath , 'rb' ) as f :
68- resources [url ] = f .read ()
67+ resources [key ] = f .read ()
6968 break
7069 else :
7170 raise FileNotFoundError (f'File not found: { base_path } (tried extensions: .json, .html, .txt, and no extension)' )
@@ -87,37 +86,40 @@ def _wait_next_tick(interval_seconds: int) -> None:
8786 time .sleep (next_tick - now )
8887
8988
90- def _fetch_resources (session : requests .Session , url_list : list [ str ], timeout : float ) -> dict [str , bytes ]:
89+ def _fetch_resources (session : requests .Session , url_dict : dict [ str , str ], timeout : float ) -> dict [str , bytes ]:
9190 """Fetch all resources from URLs.
9291
9392 Args:
9493 session: requests.Session to use
95- url_list: List of URLs to fetch
94+ url_dict: Dict mapping resource key to URL
9695 timeout: Request timeout in seconds
9796
9897 Returns:
99- Dict mapping URL to response bytes
98+ Dict mapping resource key to response bytes
10099 """
101100 resources = {}
102- for url in url_list :
101+ for key , url in url_dict . items () :
103102 r = session .get (url , timeout = timeout )
104103 r .raise_for_status ()
105- resources [url ] = r .content
104+ resources [key ] = r .content
106105 return resources
107106
108107
109- def _save_resources (resources : dict [str , bytes ], log_dir : str , timestamp : int ) -> None :
108+ def _save_resources (resources : dict [str , bytes ], url_dict : dict [ str , str ], log_dir : str , timestamp : int ) -> None :
110109 """Save fetched resources to archive files.
111110
112111 Args:
113- resources: Dict mapping URL to bytes
112+ resources: Dict mapping resource key to bytes
113+ url_dict: Dict mapping resource key to URL (for determining file extension)
114114 log_dir: Directory to save files
115115 timestamp: Unix timestamp for filenames
116116 """
117- for url , content in resources .items ():
118- filename_base = _extract_filename_from_url (url )
117+ for key , content in resources .items ():
118+ # Use the resource key as filename base (e.g., 'problems', 'scoreboard', 'teams')
119+ filename_base = key
119120
120121 # Determine file extension from URL
122+ url = url_dict [key ]
121123 if '/api/' in url or 'json' in url .lower ():
122124 ext = '.json'
123125 else :
@@ -158,7 +160,7 @@ def scrape_main(options: argparse.Namespace) -> None:
158160 last_standings = init_feeds [types .FeedType .STANDINGS ]
159161
160162 session = requests .Session ()
161- url_list = scraper .get_urls (scoreboard_url )
163+ url_dict = scraper .get_urls (scoreboard_url )
162164
163165 # Pre-configure authentication if credentials are available
164166 if scraper .has_credentials ():
@@ -167,7 +169,7 @@ def scrape_main(options: argparse.Namespace) -> None:
167169
168170 logging .info ('Attempting an initial scrape...' )
169171 try :
170- resources = _fetch_resources (session , url_list , options .interval_seconds * 0.9 )
172+ resources = _fetch_resources (session , url_dict , options .interval_seconds * 0.9 )
171173 scraper .scrape (resources )
172174 except Exception :
173175 logging .exception ('Unhandled exception' )
@@ -198,8 +200,8 @@ def scrape_main(options: argparse.Namespace) -> None:
198200 try :
199201 logging .info ('Scraping...%s' % ('' if options .upload and upload else ' (dry-run)' ))
200202 timestamp = int (time .time ())
201- resources = _fetch_resources (session , url_list , options .interval_seconds * 0.9 )
202- _save_resources (resources , log_dir , timestamp )
203+ resources = _fetch_resources (session , url_dict , options .interval_seconds * 0.9 )
204+ _save_resources (resources , url_dict , log_dir , timestamp )
203205
204206 try :
205207 standings = scraper .scrape (resources )
0 commit comments