mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 21:04: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,55 +27,59 @@ 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
|
||||||
Returns (downloads, is_valid) tuple where is_valid is True if cache is valid
|
Returns (downloads, is_valid) tuple where is_valid is True if cache is valid
|
||||||
"""
|
"""
|
||||||
cache_path = get_cache_path(package_name)
|
cache_path = get_cache_path(package_name)
|
||||||
|
|
||||||
if not os.path.exists(cache_path):
|
if not os.path.exists(cache_path):
|
||||||
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)
|
||||||
|
|
||||||
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
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error writing to cache: {e}", file=sys.stderr)
|
print(f"Error writing to cache: {e}", file=sys.stderr)
|
||||||
|
@ -92,9 +96,9 @@ def get_downloads_from_bigquery(credentials_path=None, package_name="aider-chat"
|
||||||
if is_valid:
|
if is_valid:
|
||||||
print(f"Using cached download statistics for {package_name} (valid for 24 hours)")
|
print(f"Using cached download statistics for {package_name} (valid for 24 hours)")
|
||||||
return cached_downloads
|
return cached_downloads
|
||||||
|
|
||||||
print(f"Cache invalid or expired, fetching fresh download statistics for {package_name}")
|
print(f"Cache invalid or expired, fetching fresh download statistics for {package_name}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Initialize credentials if path provided
|
# Initialize credentials if path provided
|
||||||
credentials = None
|
credentials = None
|
||||||
|
@ -410,7 +414,7 @@ def get_badges_html():
|
||||||
def main():
|
def main():
|
||||||
# Load environment variables from .env file
|
# Load environment variables from .env file
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
# Ensure cache directory exists
|
# Ensure cache directory exists
|
||||||
ensure_cache_dir()
|
ensure_cache_dir()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue