autopushed
This commit is contained in:
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
# https://click.palletsprojects.com/en/8.1.x/arguments/
|
||||
# https://click.palletsprojects.com/en/8.1.x/options/
|
||||
|
||||
import click
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
|
||||
def get_moon_phase(date_obj):
|
||||
"""Calculates an approximate moon phase name and emoji for a given date."""
|
||||
# Known new moon reference date: 2000-01-06
|
||||
ref = datetime.date(2000, 1, 6)
|
||||
days = (date_obj - ref).days
|
||||
lunation = 29.53058867
|
||||
phase = (days % lunation) / lunation
|
||||
|
||||
if phase < 0.03 or phase > 0.97:
|
||||
return "🌑 [[New Moon]]"
|
||||
elif phase < 0.22:
|
||||
return "🌒 [[Waxing Crescent]]"
|
||||
elif phase < 0.28:
|
||||
return "🌓 [[First Quarter]]"
|
||||
elif phase < 0.47:
|
||||
return "🌔 [[Waxing Gibbous]]"
|
||||
elif phase < 0.53:
|
||||
return "🌕 [[Full Moon]]"
|
||||
elif phase < 0.72:
|
||||
return "🌖 [[Waning Gibbous]]"
|
||||
elif phase < 0.78:
|
||||
return "🌗 [[Third Quarter]]"
|
||||
else:
|
||||
return "🌘 [[Waning Crescent]]"
|
||||
|
||||
|
||||
class AgoraCmd(click.Command):
|
||||
def format_help(self, ctx, formatter):
|
||||
click.echo("""Usage:
|
||||
- Visit anagora.org/date to execute this file in the Agora of Flancia.
|
||||
- Visit e.g. anagora.org/date/2026-08-15 to render date UX and past year links.
|
||||
""")
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
try:
|
||||
return super(AgoraCmd, self).__call__(
|
||||
*args, standalone_mode=False, **kwargs)
|
||||
except click.MissingParameter as exc:
|
||||
exc.ctx = None
|
||||
exc.show(file=sys.stdout)
|
||||
click.echo()
|
||||
try:
|
||||
super(AgoraCmd, self).__call__(['--help'])
|
||||
except SystemExit:
|
||||
sys.exit(exc.exit_code)
|
||||
|
||||
|
||||
@click.command(cls=AgoraCmd)
|
||||
@click.argument('date_str', type=click.STRING)
|
||||
def date_node(date_str):
|
||||
"""Renders date UX, temporal metadata, and 'On This Day' links for YYYY-MM-DD nodes."""
|
||||
try:
|
||||
dt = datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
|
||||
except ValueError:
|
||||
click.echo(f"[[{date_str}]] is not in YYYY-MM-DD date format.")
|
||||
return
|
||||
|
||||
prev_day = (dt - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
||||
next_day = (dt + datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
||||
|
||||
day_name = dt.strftime("%A")
|
||||
month_name = dt.strftime("%B")
|
||||
day_of_year = dt.timetuple().tm_yday
|
||||
iso_week = dt.isocalendar()[1]
|
||||
moon = get_moon_phase(dt)
|
||||
|
||||
click.echo(f"📅 **Date UX for [[{date_str}]]**")
|
||||
click.echo(f"◀️ Previous: [[{prev_day}]] | ▶️ Next: [[{next_day}]]\n")
|
||||
|
||||
click.echo(f"• Day of week: [[{day_name}]]")
|
||||
click.echo(f"• Month: [[{month_name}]]")
|
||||
click.echo(f"• Day of year: [[day/{day_of_year}]] (Week [[week/{iso_week}]])")
|
||||
click.echo(f"• Moon phase: {moon}\n")
|
||||
|
||||
# On This Day past links (look back up to 10 years)
|
||||
click.echo("📜 **On This Day in Past Years:**")
|
||||
past_links = []
|
||||
for y_offset in range(1, 11):
|
||||
past_year = dt.year - y_offset
|
||||
try:
|
||||
past_date = datetime.date(past_year, dt.month, dt.day).strftime("%Y-%m-%d")
|
||||
past_links.append(f"[[{past_date}]] ({y_offset}y ago)")
|
||||
except ValueError:
|
||||
# Handles leap day Feb 29 on non-leap years
|
||||
continue
|
||||
|
||||
click.echo(" " + " • ".join(past_links))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
date_node()
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
# https://click.palletsprojects.com/en/8.1.x/arguments/
|
||||
# https://click.palletsprojects.com/en/8.1.x/options/
|
||||
|
||||
import click
|
||||
import math
|
||||
import sys
|
||||
|
||||
|
||||
def get_prime_factors(n):
|
||||
"""Returns unique prime factors of n."""
|
||||
factors = []
|
||||
d = 2
|
||||
temp = abs(n)
|
||||
while d * d <= temp:
|
||||
while temp % d == 0:
|
||||
if d not in factors:
|
||||
factors.append(d)
|
||||
temp //= d
|
||||
d += 1
|
||||
if temp > 1 and temp not in factors:
|
||||
factors.append(temp)
|
||||
return factors
|
||||
|
||||
|
||||
class AgoraCmd(click.Command):
|
||||
def format_help(self, ctx, formatter):
|
||||
click.echo("""Usage:
|
||||
- Visit anagora.org/synth to execute this file in the Agora of Flancia.
|
||||
- Visit e.g. anagora.org/synth/440 to render an interactive Web Audio synth for 440 Hz.
|
||||
""")
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
try:
|
||||
return super(AgoraCmd, self).__call__(
|
||||
*args, standalone_mode=False, **kwargs)
|
||||
except click.MissingParameter as exc:
|
||||
exc.ctx = None
|
||||
exc.show(file=sys.stdout)
|
||||
click.echo()
|
||||
try:
|
||||
super(AgoraCmd, self).__call__(['--help'])
|
||||
except SystemExit:
|
||||
sys.exit(exc.exit_code)
|
||||
|
||||
|
||||
@click.command(cls=AgoraCmd)
|
||||
@click.argument('n', type=click.INT)
|
||||
def synth(n):
|
||||
"""Renders a Web Audio synth widget for number N and its prime factor harmonics."""
|
||||
if n <= 0:
|
||||
click.echo("Please enter a positive integer frequency.")
|
||||
return
|
||||
|
||||
# Scale frequency into audible pitch range (110 Hz - 1760 Hz) if needed
|
||||
base_freq = float(n)
|
||||
while base_freq < 100:
|
||||
base_freq *= 2
|
||||
while base_freq > 2000:
|
||||
base_freq /= 2
|
||||
|
||||
factors = get_prime_factors(n)
|
||||
harmonics = [round(base_freq * f, 1) for f in (factors if factors else [1])]
|
||||
|
||||
click.echo(f"🎵 **Harmonic Synthesizer for [[{n}]]** (Base: `{base_freq:.1f} Hz`)")
|
||||
if factors:
|
||||
factor_links = ", ".join(f"[[{f}]]" for f in factors)
|
||||
click.echo(f"Prime factor harmonics: {factor_links} → `{harmonics} Hz`\n")
|
||||
|
||||
# Embedded Web Audio API controls
|
||||
html_widget = f"""<div class="agora-synth-widget" style="border: 1px solid var(--border-color, #ccc); padding: 12px; border-radius: 8px; max-width: 420px; background: rgba(0,0,0,0.03);">
|
||||
<div style="margin-bottom: 8px; font-weight: bold;">🎹 Listen to [[{n}]] ({base_freq:.1f} Hz)</div>
|
||||
<button onclick="playAgoraTone('{n}', {base_freq}, {harmonics})" style="padding: 6px 14px; margin-right: 8px; cursor: pointer;">▶ Play Harmony</button>
|
||||
<button onclick="stopAgoraTone('{n}')" style="padding: 6px 14px; cursor: pointer;">⏹ Stop</button>
|
||||
<script>
|
||||
if (!window.agoraSynths) window.agoraSynths = {{}};
|
||||
function playAgoraTone(id, base, harm) {{
|
||||
stopAgoraTone(id);
|
||||
const ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
const master = ctx.createGain();
|
||||
master.gain.value = 0.15;
|
||||
master.connect(ctx.destination);
|
||||
|
||||
const freqs = [base, ...harm];
|
||||
const oscs = freqs.map(f => {{
|
||||
const osc = ctx.createOscillator();
|
||||
osc.type = 'sine';
|
||||
osc.frequency.value = f;
|
||||
osc.connect(master);
|
||||
osc.start();
|
||||
return osc;
|
||||
}});
|
||||
|
||||
window.agoraSynths[id] = {{ ctx, oscs }};
|
||||
}}
|
||||
function stopAgoraTone(id) {{
|
||||
if (window.agoraSynths && window.agoraSynths[id]) {{
|
||||
window.agoraSynths[id].oscs.forEach(o => o.stop());
|
||||
window.agoraSynths[id].ctx.close();
|
||||
delete window.agoraSynths[id];
|
||||
}}
|
||||
}}
|
||||
</script>
|
||||
</div>"""
|
||||
click.echo(html_widget)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
synth()
|
||||
Executable
+86
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
# https://click.palletsprojects.com/en/8.1.x/arguments/
|
||||
# https://click.palletsprojects.com/en/8.1.x/options/
|
||||
|
||||
import click
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
MAJOR_ARCANA = [
|
||||
"0. [[The Fool]]",
|
||||
"I. [[The Magician]]",
|
||||
"II. [[The High Priestess]]",
|
||||
"III. [[The Empress]]",
|
||||
"IV. [[The Emperor]]",
|
||||
"V. [[The Hierophant]]",
|
||||
"VI. [[The Lovers]]",
|
||||
"VII. [[The Chariot]]",
|
||||
"VIII. [[Strength]]",
|
||||
"IX. [[The Hermit]]",
|
||||
"X. [[Wheel of Fortune]]",
|
||||
"XI. [[Justice]]",
|
||||
"XII. [[The Hanged Man]]",
|
||||
"XIII. [[Death]]",
|
||||
"XIV. [[Temperance]]",
|
||||
"XV. [[The Devil]]",
|
||||
"XVI. [[The Tower]]",
|
||||
"XVII. [[The Star]]",
|
||||
"XVIII. [[The Moon]]",
|
||||
"XIX. [[The Sun]]",
|
||||
"XX. [[Judgement]]",
|
||||
"XXI. [[The World]]",
|
||||
]
|
||||
|
||||
SUITS = ["Cups", "Pentacles", "Swords", "Wands"]
|
||||
RANKS = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Page", "Knight", "Queen", "King"]
|
||||
|
||||
|
||||
def get_tarot_card(seed_str):
|
||||
"""Deterministically draws a Tarot card given a seed string."""
|
||||
h = hashlib.sha256(seed_str.encode('utf-8')).hexdigest()
|
||||
val = int(h[:8], 16)
|
||||
|
||||
# 22 Major Arcana + 56 Minor Arcana = 78 total
|
||||
idx = val % 78
|
||||
|
||||
if idx < 22:
|
||||
return MAJOR_ARCANA[idx]
|
||||
else:
|
||||
minor_idx = idx - 22
|
||||
suit = SUITS[minor_idx // 14]
|
||||
rank = RANKS[minor_idx % 14]
|
||||
return f"[[{rank} of {suit}]]"
|
||||
|
||||
|
||||
class AgoraCmd(click.Command):
|
||||
def format_help(self, ctx, formatter):
|
||||
click.echo("""Usage:
|
||||
- Visit anagora.org/tarot to execute this file in the Agora of Flancia.
|
||||
- Visit e.g. anagora.org/tarot/topic or anagora.org/tarot/42 to draw a deterministic card for that node.
|
||||
""")
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
try:
|
||||
return super(AgoraCmd, self).__call__(
|
||||
*args, standalone_mode=False, **kwargs)
|
||||
except click.MissingParameter as exc:
|
||||
exc.ctx = None
|
||||
exc.show(file=sys.stdout)
|
||||
click.echo()
|
||||
try:
|
||||
super(AgoraCmd, self).__call__(['--help'])
|
||||
except SystemExit:
|
||||
sys.exit(exc.exit_code)
|
||||
|
||||
|
||||
@click.command(cls=AgoraCmd)
|
||||
@click.argument('topic', type=click.STRING)
|
||||
def tarot(topic):
|
||||
"""Draws a deterministic Tarot card for any node or seed."""
|
||||
card = get_tarot_card(topic)
|
||||
click.echo(f"🔮 **Tarot Synchronicity for [[{topic}]]**:")
|
||||
click.echo(f" 🎴 Card: {card}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
tarot()
|
||||
Reference in New Issue
Block a user