diff --git a/addCoin.py b/addCoin.py
index 903ddd0..dc69767 100644
--- a/addCoin.py
+++ b/addCoin.py
@@ -1,35 +1,38 @@
import os
import json
-if not os.path.exists('.well-known/wallets'):
- os.makedirs('.well-known/wallets')
+if not os.path.exists(".well-known/wallets"):
+ os.makedirs(".well-known/wallets")
-def addCoin(token:str, name:str, address:str):
- with open('.well-known/wallets/'+token.upper(),'w') as f:
+
+def addCoin(token: str, name: str, address: str):
+ with open(".well-known/wallets/" + token.upper(), "w") as f:
f.write(address)
-
- with open('.well-known/wallets/.coins','r') as f:
+
+ with open(".well-known/wallets/.coins", "r") as f:
coins = json.load(f)
-
- coins[token.upper()] = f'{name} ({token.upper()})'
- with open('.well-known/wallets/.coins','w') as f:
+
+ coins[token.upper()] = f"{name} ({token.upper()})"
+ with open(".well-known/wallets/.coins", "w") as f:
f.write(json.dumps(coins, indent=4))
-def addDomain(token:str, domain:str):
- with open('.well-known/wallets/.domains','r') as f:
+
+def addDomain(token: str, domain: str):
+ with open(".well-known/wallets/.domains", "r") as f:
domains = json.load(f)
-
+
domains[token.upper()] = domain
- with open('.well-known/wallets/.domains','w') as f:
+ with open(".well-known/wallets/.domains", "w") as f:
f.write(json.dumps(domains, indent=4))
-if __name__ == '__main__':
+
+if __name__ == "__main__":
# Ask user for token
- token = input('Enter token symbol: ')
- name = input('Enter token name: ')
- address = input('Enter wallet address: ')
+ token = input("Enter token symbol: ")
+ name = input("Enter token name: ")
+ address = input("Enter wallet address: ")
addCoin(token, name, address)
- if input('Do you want to add a domain? (y/n): ').lower() == 'y':
- domain = input('Enter domain: ')
- addDomain(token, domain)
\ No newline at end of file
+ if input("Do you want to add a domain? (y/n): ").lower() == "y":
+ domain = input("Enter domain: ")
+ addDomain(token, domain)
diff --git a/blueprints/acme.py b/blueprints/acme.py
index bf1e3c2..2e283fe 100644
--- a/blueprints/acme.py
+++ b/blueprints/acme.py
@@ -3,7 +3,7 @@ import os
from cloudflare import Cloudflare
from tools import json_response
-app = Blueprint('acme', __name__)
+app = Blueprint("acme", __name__)
@app.route("/hnsdoh-acme", methods=["POST"])
@@ -23,7 +23,9 @@ def post():
zone = cf.zones.list(name="hnsdoh.com").to_dict()
zone_id = zone["result"][0]["id"] # type: ignore
existing_records = cf.dns.records.list(
- zone_id=zone_id, type="TXT", name="_acme-challenge.hnsdoh.com" # type: ignore
+ zone_id=zone_id,
+ type="TXT",
+ name="_acme-challenge.hnsdoh.com", # type: ignore
).to_dict()
record_id = existing_records["result"][0]["id"] # type: ignore
cf.dns.records.delete(dns_record_id=record_id, zone_id=zone_id)
diff --git a/blueprints/api.py b/blueprints/api.py
index f7c98cc..e3bf440 100644
--- a/blueprints/api.py
+++ b/blueprints/api.py
@@ -18,7 +18,7 @@ HTTP_NOT_FOUND = 404
HTTP_UNSUPPORTED_MEDIA = 415
HTTP_SERVER_ERROR = 500
-app = Blueprint('api', __name__, url_prefix='/api/v1')
+app = Blueprint("api", __name__, url_prefix="/api/v1")
# Register solana blueprint
app.register_blueprint(sol.app)
@@ -27,34 +27,38 @@ app.register_blueprint(sol.app)
@app.route("/help")
def help():
"""Provide API documentation and help."""
- return jsonify({
- "message": "Welcome to Nathan.Woodburn/ API! This is a personal website. For more information, visit https://nathan.woodburn.au",
- "endpoints": {
- "/time": "Get the current time",
- "/timezone": "Get the current timezone",
- "/message": "Get the message from the config",
- "/project": "Get the current project from git",
- "/version": "Get the current version of the website",
- "/page_date?url=URL&verbose=BOOL": "Get the last modified date of a webpage (verbose is optional, default false)",
- "/tools": "Get a list of tools used by Nathan Woodburn",
- "/playing": "Get the currently playing Spotify track",
- "/status": "Just check if the site is up",
- "/ping": "Just check if the site is up",
- "/ip": "Get your IP address",
- "/headers": "Get your request headers",
- "/help": "Get this help message"
- },
- "base_url": "/api/v1",
- "version": getGitCommit(),
- "ip": getClientIP(request),
- "status": HTTP_OK
- })
+ return jsonify(
+ {
+ "message": "Welcome to Nathan.Woodburn/ API! This is a personal website. For more information, visit https://nathan.woodburn.au",
+ "endpoints": {
+ "/time": "Get the current time",
+ "/timezone": "Get the current timezone",
+ "/message": "Get the message from the config",
+ "/project": "Get the current project from git",
+ "/version": "Get the current version of the website",
+ "/page_date?url=URL&verbose=BOOL": "Get the last modified date of a webpage (verbose is optional, default false)",
+ "/tools": "Get a list of tools used by Nathan Woodburn",
+ "/playing": "Get the currently playing Spotify track",
+ "/status": "Just check if the site is up",
+ "/ping": "Just check if the site is up",
+ "/ip": "Get your IP address",
+ "/headers": "Get your request headers",
+ "/help": "Get this help message",
+ },
+ "base_url": "/api/v1",
+ "version": getGitCommit(),
+ "ip": getClientIP(request),
+ "status": HTTP_OK,
+ }
+ )
+
@app.route("/status")
@app.route("/ping")
def status():
return json_response(request, "200 OK", HTTP_OK)
+
@app.route("/version")
def version():
"""Get the current version of the website."""
@@ -68,45 +72,44 @@ def time():
timezone_offset = datetime.timedelta(hours=nc_config["time-zone"])
timezone = datetime.timezone(offset=timezone_offset)
current_time = datetime.datetime.now(tz=timezone)
- return jsonify({
- "timestring": current_time.strftime("%A, %B %d, %Y %I:%M %p"),
- "timestamp": current_time.timestamp(),
- "timezone": nc_config["time-zone"],
- "timeISO": current_time.isoformat(),
- "ip": getClientIP(request),
- "status": HTTP_OK
- })
+ return jsonify(
+ {
+ "timestring": current_time.strftime("%A, %B %d, %Y %I:%M %p"),
+ "timestamp": current_time.timestamp(),
+ "timezone": nc_config["time-zone"],
+ "timeISO": current_time.isoformat(),
+ "ip": getClientIP(request),
+ "status": HTTP_OK,
+ }
+ )
@app.route("/timezone")
def timezone():
"""Get the current timezone setting."""
nc_config = get_nc_config()
- return jsonify({
- "timezone": nc_config["time-zone"],
- "ip": getClientIP(request),
- "status": HTTP_OK
- })
+ return jsonify(
+ {
+ "timezone": nc_config["time-zone"],
+ "ip": getClientIP(request),
+ "status": HTTP_OK,
+ }
+ )
@app.route("/message")
def message():
"""Get the message from the configuration."""
nc_config = get_nc_config()
- return jsonify({
- "message": nc_config["message"],
- "ip": getClientIP(request),
- "status": HTTP_OK
- })
+ return jsonify(
+ {"message": nc_config["message"], "ip": getClientIP(request), "status": HTTP_OK}
+ )
@app.route("/ip")
def ip():
"""Get the client's IP address."""
- return jsonify({
- "ip": getClientIP(request),
- "status": HTTP_OK
- })
+ return jsonify({"ip": getClientIP(request), "status": HTTP_OK})
@app.route("/email", methods=["POST"])
@@ -114,7 +117,9 @@ def email_post():
"""Send an email via the API (requires API key)."""
# Verify json
if not request.is_json:
- return json_response(request, "415 Unsupported Media Type", HTTP_UNSUPPORTED_MEDIA)
+ return json_response(
+ request, "415 Unsupported Media Type", HTTP_UNSUPPORTED_MEDIA
+ )
# Check if api key sent
data = request.json
@@ -137,7 +142,7 @@ def project():
git = get_git_latest_activity()
repo_name = git["repo"]["name"].lower()
repo_description = git["repo"]["description"]
-
+
gitinfo = {
"name": repo_name,
"description": repo_description,
@@ -145,13 +150,16 @@ def project():
"website": git["repo"].get("website"),
}
- return jsonify({
- "repo_name": repo_name,
- "repo_description": repo_description,
- "repo": gitinfo,
- "ip": getClientIP(request),
- "status": HTTP_OK
- })
+ return jsonify(
+ {
+ "repo_name": repo_name,
+ "repo_description": repo_description,
+ "repo": gitinfo,
+ "ip": getClientIP(request),
+ "status": HTTP_OK,
+ }
+ )
+
@app.route("/tools")
def tools():
@@ -161,9 +169,10 @@ def tools():
except Exception as e:
print(f"Error getting tools data: {e}")
return json_response(request, "500 Internal Server Error", HTTP_SERVER_ERROR)
-
+
return json_response(request, {"tools": tools}, HTTP_OK)
+
@app.route("/playing")
def playing():
"""Get the currently playing Spotify track."""
@@ -185,16 +194,12 @@ def headers():
if key.startswith("X-"):
# Remove from headers
toremove.append(key)
-
for key in toremove:
headers.pop(key)
- return jsonify({
- "headers": headers,
- "ip": getClientIP(request),
- "status": HTTP_OK
- })
+ return jsonify({"headers": headers, "ip": getClientIP(request), "status": HTTP_OK})
+
@app.route("/page_date")
def page_date():
@@ -211,33 +216,33 @@ def page_date():
r = requests.get(url, timeout=5)
r.raise_for_status()
except requests.exceptions.RequestException as e:
- return json_response(request, f"400 Bad Request 'url' unreachable: {e}", HTTP_BAD_REQUEST)
+ return json_response(
+ request, f"400 Bad Request 'url' unreachable: {e}", HTTP_BAD_REQUEST
+ )
page_text = r.text
# Remove ordinal suffixes globally
- page_text = re.sub(r'(\d+)(st|nd|rd|th)', r'\1', page_text, flags=re.IGNORECASE)
+ page_text = re.sub(r"(\d+)(st|nd|rd|th)", r"\1", page_text, flags=re.IGNORECASE)
# Remove HTML comments
- page_text = re.sub(r'', '', page_text, flags=re.DOTALL)
+ page_text = re.sub(r"", "", page_text, flags=re.DOTALL)
date_patterns = [
- r'(\d{4})[/-](\d{1,2})[/-](\d{1,2})', # YYYY-MM-DD
- r'(\d{1,2})[/-](\d{1,2})[/-](\d{4})', # DD-MM-YYYY
- r'(?:Last updated:|Updated:|Updated last:)?\s*(\d{1,2})\s+([A-Za-z]{3,9})[, ]?\s*(\d{4})', # DD Month YYYY
- r'(?:\b\w+\b\s+){0,3}([A-Za-z]{3,9})\s+(\d{1,2}),?\s*(\d{4})', # Month DD, YYYY with optional words
- r'\b(\d{4})(\d{2})(\d{2})\b', # YYYYMMDD
- r'(?:Last updated:|Updated:|Last update)?\s*([A-Za-z]{3,9})\s+(\d{4})', # Month YYYY only
+ r"(\d{4})[/-](\d{1,2})[/-](\d{1,2})", # YYYY-MM-DD
+ r"(\d{1,2})[/-](\d{1,2})[/-](\d{4})", # DD-MM-YYYY
+ r"(?:Last updated:|Updated:|Updated last:)?\s*(\d{1,2})\s+([A-Za-z]{3,9})[, ]?\s*(\d{4})", # DD Month YYYY
+ r"(?:\b\w+\b\s+){0,3}([A-Za-z]{3,9})\s+(\d{1,2}),?\s*(\d{4})", # Month DD, YYYY with optional words
+ r"\b(\d{4})(\d{2})(\d{2})\b", # YYYYMMDD
+ r"(?:Last updated:|Updated:|Last update)?\s*([A-Za-z]{3,9})\s+(\d{4})", # Month YYYY only
]
-
-
# Structured data patterns
json_date_patterns = {
r'"datePublished"\s*:\s*"([^"]+)"': "published",
r'"dateModified"\s*:\s*"([^"]+)"': "modified",
r']*?)property\s*=\s*"article:published_time"\s+content\s*=\s*"([^"]+)"': "published",
r']*?)property\s*=\s*"article:modified_time"\s+content\s*=\s*"([^"]+)"': "modified",
- r'