@@ -75,7 +75,7 @@ def get_live_fixtures(league_ids, api_client=None):
7575 )
7676 return response .get ("response" , [])
7777 except requests .exceptions .RequestException as e :
78- logger .error (f "Error fetching live fixtures: { e } " )
78+ logger .error ("Error fetching live fixtures: %s" , e )
7979 return []
8080
8181 # Fallback to direct requests if no api_client provided
@@ -89,7 +89,7 @@ def get_live_fixtures(league_ids, api_client=None):
8989 response .raise_for_status ()
9090 return response .json ()["response" ]
9191 except requests .exceptions .RequestException as e :
92- logger .error (f "Error fetching live fixtures: { e } " )
92+ logger .error ("Error fetching live fixtures: %s" , e )
9393 return []
9494
9595
@@ -112,8 +112,9 @@ def get_league_table(league_id: int) -> List[Dict[str, Any]]:
112112 cache_entry = _table_cache [league_id ]
113113 if now < cache_entry ["expires" ]:
114114 logger .debug (
115- f"Using cached table for league { league_id } "
116- f"(expires in { int (cache_entry ['expires' ] - now )} s)"
115+ "Using cached table for league %s (expires in %ds)" ,
116+ league_id ,
117+ int (cache_entry ["expires" ] - now )
117118 )
118119 return cache_entry ["data" ]
119120
@@ -136,19 +137,42 @@ def get_league_table(league_id: int) -> List[Dict[str, Any]]:
136137 "data" : table_data ,
137138 "expires" : now + TABLE_CACHE_SECONDS ,
138139 }
139- logger .info (f "Fetched and cached table for league { league_id } " )
140+ logger .info ("Fetched and cached table for league %s" , league_id )
140141 return table_data
141142
142143 except requests .exceptions .RequestException as e :
143- logger .error (f "Error getting league table for { league_id } : { e } " )
144+ logger .error ("Error getting league table for %s: %s" , league_id , e )
144145
145146 # Return stale cache if available, otherwise empty
146147 if league_id in _table_cache :
147- logger .warning (f "Using stale cache for league { league_id } " )
148+ logger .warning ("Using stale cache for league %s" , league_id )
148149 return _table_cache [league_id ]["data" ]
149150 return []
150151
151152
153+ def _format_match_date_section (date_str , matches_list ):
154+ """Format matches for a single date into a markdown section."""
155+ date_extracted = datetime .strptime (date_str , "%Y-%m-%d" )
156+ date_header = date_extracted .strftime (
157+ f"%A, %B { ordinal_suffix (date_extracted .day )} "
158+ )
159+ section_header = f"## { date_header } \n \n "
160+
161+ matches = [format_live_fixture (match ) for match in matches_list ]
162+ match_table = tabulate (
163+ matches , headers = match_table_headers , tablefmt = 'pipe'
164+ )
165+
166+ section = f"{ section_header } { match_table } \n "
167+ for match in matches_list :
168+ scorers = format_scorers_inline (match )
169+ if scorers :
170+ section += f"\n { scorers } \n "
171+ section += "\n "
172+
173+ return section
174+
175+
152176def build_premier_body (matches_data , league_table , gameweek_number ):
153177 """Build the body text for Premier Division post."""
154178 matches_by_date = {}
@@ -159,25 +183,7 @@ def build_premier_body(matches_data, league_table, gameweek_number):
159183 body = "*Live scores will be updated during matches*\n \n "
160184
161185 for date , matches_list in sorted (matches_by_date .items ()):
162- date_extracted = datetime .strptime (date , "%Y-%m-%d" )
163- date_header = date_extracted .strftime (
164- f"%A, %B { ordinal_suffix (date_extracted .day )} "
165- )
166- section_header = f"## { date_header } \n \n "
167-
168- matches = [format_live_fixture (match ) for match in matches_list ]
169-
170- match_table = tabulate (
171- matches , headers = match_table_headers , tablefmt = 'pipe'
172- )
173- body += f"{ section_header } { match_table } \n "
174-
175- # Add scorers inline under table
176- for match in matches_list :
177- scorers = format_scorers_inline (match )
178- if scorers :
179- body += f"\n { scorers } \n "
180- body += "\n "
186+ body += _format_match_date_section (date , matches_list )
181187
182188 table_data = [
183189 [
@@ -226,25 +232,7 @@ def build_first_body(matches_data, league_table, gameweek_number):
226232 body = "*Live scores will be updated during matches*\n \n "
227233
228234 for date , matches_list in sorted (matches_by_date .items ()):
229- date_extracted = datetime .strptime (date , "%Y-%m-%d" )
230- date_header = date_extracted .strftime (
231- f"%A, %B { ordinal_suffix (date_extracted .day )} "
232- )
233- section_header = f"## { date_header } \n \n "
234-
235- matches = [format_live_fixture (match ) for match in matches_list ]
236-
237- match_table = tabulate (
238- matches , headers = match_table_headers , tablefmt = 'pipe'
239- )
240- body += f"{ section_header } { match_table } \n "
241-
242- # Add scorers inline under table
243- for match in matches_list :
244- scorers = format_scorers_inline (match )
245- if scorers :
246- body += f"\n { scorers } \n "
247- body += "\n "
235+ body += _format_match_date_section (date , matches_list )
248236
249237 table_data = [
250238 [
@@ -349,13 +337,13 @@ def update_reddit_post(post_id: str, new_body: str) -> bool:
349337
350338 post = reddit .submission (id = post_id )
351339 post .edit (new_body )
352- logger .info (f "Updated post { post_id } " )
340+ logger .info ("Updated post %s" , post_id )
353341 return True
354342 except (
355343 praw .exceptions .PRAWException ,
356344 requests .exceptions .RequestException
357345 ) as e :
358- logger .error (f "Error updating post { post_id } : { e } " )
346+ logger .error ("Error updating post %s: %s" , post_id , e )
359347 return False
360348
361349
@@ -374,7 +362,7 @@ def update_league_thread(
374362 league_id: League ID (357, 358, or 359)
375363 """
376364 comp_display = competition_name .replace ('_' , ' ' ).title ()
377- logger .info (f "Updating { comp_display } thread..." )
365+ logger .info ("Updating %s thread..." , comp_display )
378366
379367 post_id = cache_data ["post_id" ]
380368 current_round = cache_data ["round" ]
@@ -413,7 +401,7 @@ def main():
413401 break
414402
415403 if not has_matches_today :
416- logger .info (f "No matches scheduled for { today . isoformat () } , exiting." )
404+ logger .info ("No matches scheduled for %s , exiting." , today . isoformat () )
417405 return
418406
419407 # Initialize API client with rate limiting
@@ -427,13 +415,15 @@ def main():
427415 logger .info ("No live fixtures found." )
428416 return
429417
430- logger .info (f "Found { len ( live_fixtures ) } live fixtures" )
418+ logger .info ("Found %d live fixtures" , len ( live_fixtures ) )
431419
432420 # Log rate limiting stats
433421 stats = rate_limiter .get_stats ()
434422 logger .info (
435- f"Rate limiting stats: { stats ['daily_calls' ]} /{ stats ['daily_limit' ]} "
436- f"calls today, polling interval: { stats ['polling_interval' ]} s"
423+ "Rate limiting stats: %s/%s calls today, polling interval: %ss" ,
424+ stats ['daily_calls' ],
425+ stats ['daily_limit' ],
426+ stats ['polling_interval' ]
437427 )
438428
439429 # Organize fixtures by league
@@ -472,10 +462,7 @@ def main():
472462 logger .info ("All matches finished." )
473463 else :
474464 next_poll = rate_limiter .get_polling_interval ()
475- logger .info (
476- f"Some matches still in progress. "
477- f"Next poll in { next_poll } s."
478- )
465+ logger .info ("Some matches still in progress. Next poll in %ss." , next_poll )
479466
480467
481468if __name__ == "__main__" :
0 commit comments