mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 05:14:59 +00:00
style: Format code with linter
This commit is contained in:
parent
ac2439e25b
commit
4aad9fbdd4
1 changed files with 22 additions and 18 deletions
|
@ -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_DIR = os.path.expanduser("~/.cache/aider-badges")
|
||||||
CACHE_DURATION = 24 * 60 * 60 # 24 hours in seconds
|
CACHE_DURATION = 24 * 60 * 60 # 24 hours in seconds
|
||||||
|
|
||||||
|
|
||||||
def ensure_cache_dir():
|
def ensure_cache_dir():
|
||||||
"""Create the cache directory if it doesn't exist"""
|
"""Create the cache directory if it doesn't exist"""
|
||||||
os.makedirs(CACHE_DIR, exist_ok=True)
|
os.makedirs(CACHE_DIR, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
def get_cache_path(package_name):
|
def get_cache_path(package_name):
|
||||||
"""Get the path to the cache file for a package"""
|
"""Get the path to the cache file for a package"""
|
||||||
return os.path.join(CACHE_DIR, f"{package_name}_downloads.json")
|
return os.path.join(CACHE_DIR, f"{package_name}_downloads.json")
|
||||||
|
|
||||||
|
|
||||||
def read_from_cache(package_name):
|
def read_from_cache(package_name):
|
||||||
"""
|
"""
|
||||||
Read download statistics from cache if available and not expired
|
Read download statistics from cache if available and not expired
|
||||||
|
@ -46,21 +49,22 @@ def read_from_cache(package_name):
|
||||||
return None, False
|
return None, False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(cache_path, 'r') as f:
|
with open(cache_path, "r") as f:
|
||||||
cache_data = json.load(f)
|
cache_data = json.load(f)
|
||||||
|
|
||||||
# Check if cache is expired
|
# Check if cache is expired
|
||||||
timestamp = cache_data.get('timestamp', 0)
|
timestamp = cache_data.get("timestamp", 0)
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
|
|
||||||
if current_time - timestamp > CACHE_DURATION:
|
if current_time - timestamp > CACHE_DURATION:
|
||||||
return None, False
|
return None, False
|
||||||
|
|
||||||
return cache_data.get('downloads'), True
|
return cache_data.get("downloads"), True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error reading from cache: {e}", file=sys.stderr)
|
print(f"Error reading from cache: {e}", file=sys.stderr)
|
||||||
return None, False
|
return None, False
|
||||||
|
|
||||||
|
|
||||||
def write_to_cache(package_name, downloads):
|
def write_to_cache(package_name, downloads):
|
||||||
"""Write download statistics to cache"""
|
"""Write download statistics to cache"""
|
||||||
cache_path = get_cache_path(package_name)
|
cache_path = get_cache_path(package_name)
|
||||||
|
@ -68,12 +72,12 @@ def write_to_cache(package_name, downloads):
|
||||||
try:
|
try:
|
||||||
ensure_cache_dir()
|
ensure_cache_dir()
|
||||||
cache_data = {
|
cache_data = {
|
||||||
'downloads': downloads,
|
"downloads": downloads,
|
||||||
'timestamp': time.time(),
|
"timestamp": time.time(),
|
||||||
'datetime': datetime.now().isoformat()
|
"datetime": datetime.now().isoformat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(cache_path, 'w') as f:
|
with open(cache_path, "w") as f:
|
||||||
json.dump(cache_data, f)
|
json.dump(cache_data, f)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue