Initial commit - divination content
This commit is contained in:
commit
040d373967
271 changed files with 28825 additions and 0 deletions
79
extract_divination.py
Normal file
79
extract_divination.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import os
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
markdown_dir = r"c:\Users\David\Resilio Sync\CODE\disinfozone\divination\markdown"
|
||||
images_dir = r"c:\Users\David\Resilio Sync\CODE\disinfozone\divination\images"
|
||||
|
||||
essays = []
|
||||
|
||||
def parse_frontmatter(content):
|
||||
# Very basic frontmatter parser for +++ blocks
|
||||
match = re.search(r'^\+\+\+\s*(.*?)\s*\+\+\+', content, re.DOTALL)
|
||||
if not match:
|
||||
return None
|
||||
|
||||
fm_text = match.group(1)
|
||||
data = {}
|
||||
for line in fm_text.split('\n'):
|
||||
if '=' in line:
|
||||
key, val = line.split('=', 1)
|
||||
key = key.strip()
|
||||
val = val.strip().strip('"').strip("'")
|
||||
if key == 'images':
|
||||
# Parse list like ['/images/wide29.jpg']
|
||||
images = re.findall(r"['\"](.*?)['\"]", val)
|
||||
data[key] = images
|
||||
else:
|
||||
data[key] = val
|
||||
return data
|
||||
|
||||
for filename in os.listdir(markdown_dir):
|
||||
if filename.endswith(".md"):
|
||||
path = os.path.join(markdown_dir, filename)
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
data = parse_frontmatter(content)
|
||||
if data:
|
||||
# Add slug
|
||||
data['slug'] = filename.replace('.md', '.html')
|
||||
if data['slug'] == 'the-weight-of-wonder.html':
|
||||
data['slug'] = 'the-weight-of-wonder-v3.html'
|
||||
|
||||
# Infer sigil
|
||||
sigil = None
|
||||
if 'images' in data and data['images']:
|
||||
banner = data['images'][0]
|
||||
# banner is like '/images/wide54.jpg' or '/images/onlinemadness-wide.jpg'
|
||||
basename = os.path.basename(banner)
|
||||
name_part = basename.replace('-wide.jpg', '').replace('wide', '').replace('.jpg', '')
|
||||
|
||||
if basename.startswith('wide'):
|
||||
sigil_path = f"/images/div{name_part}.png"
|
||||
else:
|
||||
sigil_path = f"/images/{name_part}.png"
|
||||
|
||||
# Verify if sigil exists (rough check)
|
||||
# For now just use the path
|
||||
data['sigil'] = sigil_path
|
||||
|
||||
# Parse date for sorting
|
||||
# format can be 2025-02-09T13:13:13-03:33 or 2025-10-20T22:11:33
|
||||
date_str = data.get('date', '1970-01-01')
|
||||
try:
|
||||
# Strip timezone for simple sorting
|
||||
clean_date = date_str.split('T')[0]
|
||||
data['sort_date'] = datetime.strptime(clean_date, "%Y-%m-%d")
|
||||
except:
|
||||
data['sort_date'] = datetime(1970, 1, 1)
|
||||
|
||||
essays.append(data)
|
||||
|
||||
# Sort by date descending
|
||||
essays.sort(key=lambda x: x['sort_date'], reverse=True)
|
||||
|
||||
# Output summary
|
||||
print(f"Total essays found: {len(essays)}")
|
||||
for e in essays[:5]:
|
||||
print(f"[{e.get('date')}] {e.get('title')} -> {e.get('slug')}")
|
||||
print(f" Image: {e.get('images')} | Sigil: {e.get('sigil')}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue