docs(duckdns): Update status and sync to Notion

- Added analysis of latest DNS monitor logs (06.01.2026).

- Refactored sync_docs_to_notion.py to be generic and support multiple files.
This commit is contained in:
2026-01-06 20:40:04 +00:00
parent 1742b1c83b
commit bc1cff825a
2 changed files with 51 additions and 65 deletions

View File

@@ -2,10 +2,10 @@ import requests
import json
import os
import re
import sys
TOKEN_FILE = 'notion_api_key.txt'
PARENT_PAGE_ID = "2e088f42-8544-8024-8289-deb383da3818"
DOC_FILE = "notion_integration.md"
def parse_markdown_to_blocks(md_content):
blocks = []
@@ -15,25 +15,21 @@ def parse_markdown_to_blocks(md_content):
code_content = []
for line in lines:
# Don't strip indentation for code blocks, but do for logic checks
stripped = line.strip()
# Handle Code Blocks
if stripped.startswith("```"):
if in_code_block:
# End of code block
blocks.append({
"object": "block",
"type": "code",
"code": {
"rich_text": [{"type": "text", "text": {"content": "\n".join(code_content)}}],
"rich_text": [{"type": "text", "text": {"content": '\n'.join(code_content)}}],
"language": "plain text"
}
})
code_content = []
in_code_block = False
else:
# Start of code block
in_code_block = True
continue
@@ -44,52 +40,38 @@ def parse_markdown_to_blocks(md_content):
if not stripped:
continue
# Headings
if line.startswith("# "):
blocks.append({
"object": "block",
"type": "heading_1",
"heading_1": {
"rich_text": [{"type": "text", "text": {"content": line[2:]}}]
}
})
"heading_1": {"rich_text": [{"type": "text", "text": {"content": line[2:]}}]}}
)
elif line.startswith("## "):
blocks.append({
"object": "block",
"type": "heading_2",
"heading_2": {
"rich_text": [{"type": "text", "text": {"content": line[3:]}}]
}
})
"heading_2": {"rich_text": [{"type": "text", "text": {"content": line[3:]}}]}}
)
elif line.startswith("### "):
blocks.append({
"object": "block",
"type": "heading_3",
"heading_3": {
"rich_text": [{"type": "text", "text": {"content": line[4:]}}]
}
})
# List Items
"heading_3": {"rich_text": [{"type": "text", "text": {"content": line[4:]}}]}}
)
elif stripped.startswith("* ") or stripped.startswith("- "):
content = stripped[2:]
blocks.append({
"object": "block",
"type": "bulleted_list_item",
"bulleted_list_item": {
"rich_text": [{"type": "text", "text": {"content": content}}]
}
})
# Numbered List (Simple detection)
"bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": content}}]}}
)
elif re.match(r"^\d+\.", stripped):
content = re.sub(r"^\d+\.\s*", "", stripped)
blocks.append({
"object": "block",
"type": "numbered_list_item",
"numbered_list_item": {
"rich_text": [{"type": "text", "text": {"content": content}}]
}
})
# Tables (Very basic handling: convert to code block for preservation)
"numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": content}}]}}
)
elif stripped.startswith("|"):
blocks.append({
"object": "block",
@@ -99,27 +81,28 @@ def parse_markdown_to_blocks(md_content):
"language": "plain text"
}
})
# Paragraphs
else:
blocks.append({
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [{"type": "text", "text": {"content": line}}]
}
})
"paragraph": {"rich_text": [{"type": "text", "text": {"content": line}}]}}
)
return blocks
def upload_doc(token):
def upload_doc(token, file_path):
try:
with open(DOC_FILE, 'r') as f:
with open(file_path, 'r') as f:
content = f.read()
except FileNotFoundError:
print(f"Error: Could not find '{DOC_FILE}'")
print(f"Error: Could not find '{file_path}'")
return
print(f"Parsing '{DOC_FILE}'...")
title = os.path.basename(file_path)
if content.startswith("# "):
title = content.split('\n')[0][2:].strip()
print(f"Parsing '{file_path}'...")
children_blocks = parse_markdown_to_blocks(content)
url = "https://api.notion.com/v1/pages"
@@ -132,45 +115,31 @@ def upload_doc(token):
payload = {
"parent": { "page_id": PARENT_PAGE_ID },
"properties": {
"title": [
{
"text": {
"content": "📘 Notion Integration Dokumentation"
}
}
]
"title": [{"text": {"content": f"📘 {title}"}}]
},
"children": children_blocks[:100] # Safe limit
"children": children_blocks[:100]
}
print(f"Uploading to Notion under parent {PARENT_PAGE_ID}...")
print(f"Uploading '{title}' to Notion...")
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
data = response.json()
print("\n=== SUCCESS ===")
print(f"Documentation uploaded!")
print(f"URL: {data.get('url')}")
except requests.exceptions.HTTPError as e:
print(f"\n=== ERROR ===")
print(f"HTTP Error: {e}")
print(f"Response: {response.text}")
print(f"SUCCESS: {data.get('url')}")
except Exception as e:
print(f"\n=== ERROR ===")
print(f"An error occurred: {e}")
print(f"ERROR: {e}")
def main():
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python sync_docs_to_notion.py <filename>")
sys.exit(1)
try:
with open(TOKEN_FILE, 'r') as f:
token = f.read().strip()
except FileNotFoundError:
print(f"Error: Could not find '{TOKEN_FILE}'")
return
sys.exit(1)
upload_doc(token)
if __name__ == "__main__":
main()
upload_doc(token, sys.argv[1])