style: Format code with linter

This commit is contained in:
Paul Gauthier (aider) 2025-03-21 11:36:28 -07:00
parent ac2439e25b
commit 4aad9fbdd4

View file

@ -27,14 +27,17 @@ SINGULARITY_TOOLTIP = "Percentage of the new code in Aider's last release writte
CACHE_DIR = os.path.expanduser("~/.cache/aider-badges")
CACHE_DURATION = 24 * 60 * 60 # 24 hours in seconds
def ensure_cache_dir():
"""Create the cache directory if it doesn't exist"""
os.makedirs(CACHE_DIR, exist_ok=True)
def get_cache_path(package_name):
"""Get the path to the cache file for a package"""
return os.path.join(CACHE_DIR, f"{package_name}_downloads.json")
def read_from_cache(package_name):
"""
Read download statistics from cache if available and not expired
@ -46,21 +49,22 @@ def read_from_cache(package_name):
return None, False
try:
with open(cache_path, 'r') as f:
with open(cache_path, "r") as f:
cache_data = json.load(f)
# Check if cache is expired
timestamp = cache_data.get('timestamp', 0)
timestamp = cache_data.get("timestamp", 0)
current_time = time.time()
if current_time - timestamp > CACHE_DURATION:
return None, False
return cache_data.get('downloads'), True
return cache_data.get("downloads"), True
except Exception as e:
print(f"Error reading from cache: {e}", file=sys.stderr)
return None, False
def write_to_cache(package_name, downloads):
"""Write download statistics to cache"""
cache_path = get_cache_path(package_name)
@ -68,12 +72,12 @@ def write_to_cache(package_name, downloads):
try:
ensure_cache_dir()
cache_data = {
'downloads': downloads,
'timestamp': time.time(),
'datetime': datetime.now().isoformat()
"downloads": downloads,
"timestamp": time.time(),
"datetime": datetime.now().isoformat(),
}
with open(cache_path, 'w') as f:
with open(cache_path, "w") as f:
json.dump(cache_data, f)
return True