forked from ChuckBuilds/LEDMatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear_nhl_cache.py
More file actions
76 lines (60 loc) · 2.09 KB
/
clear_nhl_cache.py
File metadata and controls
76 lines (60 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""
Script to clear NHL cache so managers will fetch fresh data.
"""
import sys
import os
import json
from datetime import datetime
# Add the src directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
def clear_nhl_cache():
"""Clear NHL cache to force fresh data fetch."""
print("Clearing NHL cache...")
try:
from cache_manager import CacheManager
# Create cache manager
cache_manager = CacheManager()
# Clear NHL cache for current season
now = datetime.now()
season_year = now.year
if now.month < 9:
season_year = now.year - 1
cache_key = f"nhl_api_data_{season_year}"
print(f"Clearing cache key: {cache_key}")
# Clear the cache
cache_manager.clear_cache(cache_key)
print(f"Successfully cleared cache for {cache_key}")
# Also clear any other NHL-related cache keys
nhl_keys = [
f"nhl_api_data_{season_year}",
f"nhl_api_data_{season_year-1}",
f"nhl_api_data_{season_year+1}",
"nhl_live_games",
"nhl_recent_games",
"nhl_upcoming_games"
]
for key in nhl_keys:
try:
cache_manager.clear_cache(key)
print(f"Cleared cache key: {key}")
except:
pass # Key might not exist
print("NHL cache cleared successfully!")
print("NHL managers will now fetch fresh data from ESPN API.")
except ImportError as e:
print(f"Could not import cache manager: {e}")
print("This script needs to be run on the Raspberry Pi where the cache manager is available.")
except Exception as e:
print(f"Error clearing cache: {e}")
def main():
"""Main function."""
print("=" * 50)
print("NHL Cache Clearer")
print("=" * 50)
clear_nhl_cache()
print("\n" + "=" * 50)
print("Cache clearing complete!")
print("=" * 50)
if __name__ == "__main__":
main()