Fix trailing whitespace and finalize performance improvements
Co-authored-by: Nathanwoodburn <62039630+Nathanwoodburn@users.noreply.github.com>
This commit is contained in:
@@ -18,17 +18,17 @@ def get_nc_config():
|
|||||||
"""
|
"""
|
||||||
Get NC_CONFIG with caching (1 hour TTL).
|
Get NC_CONFIG with caching (1 hour TTL).
|
||||||
Falls back to default config on error.
|
Falls back to default config on error.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Configuration dictionary
|
dict: Configuration dictionary
|
||||||
"""
|
"""
|
||||||
global _nc_config_cache
|
global _nc_config_cache
|
||||||
current_time = datetime.datetime.now().timestamp()
|
current_time = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
# Check if cache is valid
|
# Check if cache is valid
|
||||||
if _nc_config_cache["data"] and (current_time - _nc_config_cache["timestamp"]) < _nc_config_ttl:
|
if _nc_config_cache["data"] and (current_time - _nc_config_cache["timestamp"]) < _nc_config_ttl:
|
||||||
return _nc_config_cache["data"]
|
return _nc_config_cache["data"]
|
||||||
|
|
||||||
# Fetch new config
|
# Fetch new config
|
||||||
try:
|
try:
|
||||||
config = requests.get(
|
config = requests.get(
|
||||||
@@ -53,17 +53,17 @@ _git_data_ttl = 300 # 5 minutes cache
|
|||||||
def get_git_latest_activity():
|
def get_git_latest_activity():
|
||||||
"""
|
"""
|
||||||
Get latest git activity with caching (5 minute TTL).
|
Get latest git activity with caching (5 minute TTL).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Git activity data or default values
|
dict: Git activity data or default values
|
||||||
"""
|
"""
|
||||||
global _git_data_cache
|
global _git_data_cache
|
||||||
current_time = datetime.datetime.now().timestamp()
|
current_time = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
# Check if cache is valid
|
# Check if cache is valid
|
||||||
if _git_data_cache["data"] and (current_time - _git_data_cache["timestamp"]) < _git_data_ttl:
|
if _git_data_cache["data"] and (current_time - _git_data_cache["timestamp"]) < _git_data_ttl:
|
||||||
return _git_data_cache["data"]
|
return _git_data_cache["data"]
|
||||||
|
|
||||||
# Fetch new data
|
# Fetch new data
|
||||||
try:
|
try:
|
||||||
git = requests.get(
|
git = requests.get(
|
||||||
@@ -78,11 +78,11 @@ def get_git_latest_activity():
|
|||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error fetching git data: {e}")
|
print(f"Error fetching git data: {e}")
|
||||||
|
|
||||||
# Return cached or default
|
# Return cached or default
|
||||||
if _git_data_cache["data"]:
|
if _git_data_cache["data"]:
|
||||||
return _git_data_cache["data"]
|
return _git_data_cache["data"]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"repo": {
|
"repo": {
|
||||||
"html_url": "https://nathan.woodburn.au",
|
"html_url": "https://nathan.woodburn.au",
|
||||||
@@ -100,20 +100,20 @@ _projects_ttl = 7200 # 2 hours cache
|
|||||||
def get_projects(limit=3):
|
def get_projects(limit=3):
|
||||||
"""
|
"""
|
||||||
Get projects list with caching (2 hour TTL).
|
Get projects list with caching (2 hour TTL).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
limit (int): Number of projects to return
|
limit (int): Number of projects to return
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: List of project dictionaries
|
list: List of project dictionaries
|
||||||
"""
|
"""
|
||||||
global _projects_cache
|
global _projects_cache
|
||||||
current_time = datetime.datetime.now().timestamp()
|
current_time = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
# Check if cache is valid
|
# Check if cache is valid
|
||||||
if _projects_cache["data"] and (current_time - _projects_cache["timestamp"]) < _projects_ttl:
|
if _projects_cache["data"] and (current_time - _projects_cache["timestamp"]) < _projects_ttl:
|
||||||
return _projects_cache["data"][:limit]
|
return _projects_cache["data"][:limit]
|
||||||
|
|
||||||
# Fetch new data
|
# Fetch new data
|
||||||
try:
|
try:
|
||||||
projects = []
|
projects = []
|
||||||
@@ -122,7 +122,7 @@ def get_projects(limit=3):
|
|||||||
timeout=5
|
timeout=5
|
||||||
)
|
)
|
||||||
projects = projectsreq.json()
|
projects = projectsreq.json()
|
||||||
|
|
||||||
# Check for pagination
|
# Check for pagination
|
||||||
pageNum = 2
|
pageNum = 2
|
||||||
while 'rel="next"' in projectsreq.headers.get("link", ""):
|
while 'rel="next"' in projectsreq.headers.get("link", ""):
|
||||||
@@ -135,16 +135,16 @@ def get_projects(limit=3):
|
|||||||
# Safety limit
|
# Safety limit
|
||||||
if pageNum > 10:
|
if pageNum > 10:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Process projects
|
# Process projects
|
||||||
for project in projects:
|
for project in projects:
|
||||||
if project.get("avatar_url") in ("https://git.woodburn.au/", ""):
|
if project.get("avatar_url") in ("https://git.woodburn.au/", ""):
|
||||||
project["avatar_url"] = "/favicon.png"
|
project["avatar_url"] = "/favicon.png"
|
||||||
project["name"] = project["name"].replace("_", " ").replace("-", " ")
|
project["name"] = project["name"].replace("_", " ").replace("-", " ")
|
||||||
|
|
||||||
# Sort by last updated
|
# Sort by last updated
|
||||||
projects_sorted = sorted(projects, key=lambda x: x.get("updated_at", ""), reverse=True)
|
projects_sorted = sorted(projects, key=lambda x: x.get("updated_at", ""), reverse=True)
|
||||||
|
|
||||||
# Remove duplicates by name
|
# Remove duplicates by name
|
||||||
seen_names = set()
|
seen_names = set()
|
||||||
unique_projects = []
|
unique_projects = []
|
||||||
@@ -152,7 +152,7 @@ def get_projects(limit=3):
|
|||||||
if project["name"] not in seen_names:
|
if project["name"] not in seen_names:
|
||||||
unique_projects.append(project)
|
unique_projects.append(project)
|
||||||
seen_names.add(project["name"])
|
seen_names.add(project["name"])
|
||||||
|
|
||||||
_projects_cache = {"data": unique_projects, "timestamp": current_time}
|
_projects_cache = {"data": unique_projects, "timestamp": current_time}
|
||||||
return unique_projects[:limit]
|
return unique_projects[:limit]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -170,17 +170,17 @@ _uptime_ttl = 300 # 5 minutes cache
|
|||||||
def get_uptime_status():
|
def get_uptime_status():
|
||||||
"""
|
"""
|
||||||
Get uptime status with caching (5 minute TTL).
|
Get uptime status with caching (5 minute TTL).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if services are up, False otherwise
|
bool: True if services are up, False otherwise
|
||||||
"""
|
"""
|
||||||
global _uptime_cache
|
global _uptime_cache
|
||||||
current_time = datetime.datetime.now().timestamp()
|
current_time = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
# Check if cache is valid
|
# Check if cache is valid
|
||||||
if _uptime_cache["data"] is not None and (current_time - _uptime_cache["timestamp"]) < _uptime_ttl:
|
if _uptime_cache["data"] is not None and (current_time - _uptime_cache["timestamp"]) < _uptime_ttl:
|
||||||
return _uptime_cache["data"]
|
return _uptime_cache["data"]
|
||||||
|
|
||||||
# Fetch new data
|
# Fetch new data
|
||||||
try:
|
try:
|
||||||
uptime = requests.get(
|
uptime = requests.get(
|
||||||
@@ -204,7 +204,7 @@ def get_uptime_status():
|
|||||||
def get_wallet_tokens():
|
def get_wallet_tokens():
|
||||||
"""
|
"""
|
||||||
Get wallet tokens with caching.
|
Get wallet tokens with caching.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: List of token dictionaries
|
list: List of token dictionaries
|
||||||
"""
|
"""
|
||||||
@@ -220,7 +220,7 @@ def get_wallet_tokens():
|
|||||||
def get_coin_names():
|
def get_coin_names():
|
||||||
"""
|
"""
|
||||||
Get coin names with caching.
|
Get coin names with caching.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Dictionary of coin names
|
dict: Dictionary of coin names
|
||||||
"""
|
"""
|
||||||
@@ -236,7 +236,7 @@ def get_coin_names():
|
|||||||
def get_wallet_domains():
|
def get_wallet_domains():
|
||||||
"""
|
"""
|
||||||
Get wallet domains with caching.
|
Get wallet domains with caching.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: Dictionary of wallet domains
|
dict: Dictionary of wallet domains
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ def index():
|
|||||||
custom += "<style>#downtime{display:none !important;}</style>"
|
custom += "<style>#downtime{display:none !important;}</style>"
|
||||||
else:
|
else:
|
||||||
custom += "<style>#downtime{opacity:1;}</style>"
|
custom += "<style>#downtime{opacity:1;}</style>"
|
||||||
|
|
||||||
# Special names
|
# Special names
|
||||||
if repo_name == "nathanwoodburn.github.io":
|
if repo_name == "nathanwoodburn.github.io":
|
||||||
repo_name = "Nathan.Woodburn/"
|
repo_name = "Nathan.Woodburn/"
|
||||||
@@ -429,7 +429,7 @@ def donate():
|
|||||||
domain = domains[crypto]
|
domain = domains[crypto]
|
||||||
cryptoHTML += "<br>Or send to this domain on compatible wallets:<br>"
|
cryptoHTML += "<br>Or send to this domain on compatible wallets:<br>"
|
||||||
cryptoHTML += f'<code data-bs-toggle="tooltip" data-bss-tooltip="" id="crypto-domain" class="address" style="color: rgb(242,90,5);display: block;" data-bs-original-title="Click to copy">{domain}</code>'
|
cryptoHTML += f'<code data-bs-toggle="tooltip" data-bss-tooltip="" id="crypto-domain" class="address" style="color: rgb(242,90,5);display: block;" data-bs-original-title="Click to copy">{domain}</code>'
|
||||||
|
|
||||||
if address:
|
if address:
|
||||||
cryptoHTML += (
|
cryptoHTML += (
|
||||||
'<br><img src="/address/'
|
'<br><img src="/address/'
|
||||||
|
|||||||
Reference in New Issue
Block a user