Amiga-Z Wiki

“Modern tools for old-school communities.”

User Tools

Site Tools


mystic_cal:mystic_cal_code

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
mystic_cal:mystic_cal_code [2026/02/16 16:32] – created freedomottermystic_cal:mystic_cal_code [2026/02/16 16:42] (current) freedomotter
Line 1: Line 1:
 ====== Mystic Calendar Code ====== ====== Mystic Calendar Code ======
 +
 +----
 +
 +===== 🔧 Mystic Setup =====
 +
 +
 +**In Mystic:**
 +<code>
 +Editors → Scripts → Add
 +</code>
 +
 +**Command:**
 +<code>
 +python3 scripts/calendar.py
 +</code>
 +
 +**Birthday mode:**
 +<code>
 +python3 scripts/calendar.py bd
 +</code>
 +
 +----
 +
 +===== Main Calendar Script =====
 +
 +//**scripts/calendar.py**//
 <code> <code>
 #!/usr/bin/env python3 #!/usr/bin/env python3
Line 102: Line 128:
     main()     main()
  
 +</code>
 +
 +
 +===== Birthday Generator =====
 +
 +//**scripts/generate_birthdays.py**//
 +<code>
 +#!/usr/bin/env python3
 +
 +import os
 +import datetime
 +import mystic  # Mystic's native Python module
 +
 +DATA_PATH = "../calendar_data"
 +
 +def ordinal(n):
 +    return str(n) + (
 +        "th" if 11 <= n % 100 <= 13 else
 +        {1: "st", 2: "nd", 3: "rd"}.get(n % 10, "th")
 +    )
 +
 +def generate(year):
 +    os.makedirs(DATA_PATH, exist_ok=True)
 +    filename = os.path.join(DATA_PATH, f"cal.bdays.{year}")
 +
 +    users = mystic.user_list()
 +
 +    entries = []
 +
 +    for u in users:
 +        if not u.birthdate:
 +            continue
 +
 +        bd = datetime.datetime.strptime(u.birthdate, "%m/%d/%Y")
 +        mmdd = bd.strftime("%m%d")
 +
 +        line = f"{mmdd} {ordinal(bd.day):<5}- {u.name}'s birthday!"
 +        entries.append(line)
 +
 +    entries.sort()
 +
 +    with open(filename, "w") as f:
 +        for e in entries:
 +            f.write(e + "\n")
 +
 +    print(f"Generated {filename}")
 +
 +
 +if __name__ == "__main__":
 +    year = datetime.date.today().year
 +    generate(year)
 +    generate(year + 1)
 +</code>
 +
 +===== Holiday Generator =====
 +**Install requirements:**
 +<code>
 +pip3 install requests
 +</code>
 +
 +//**scripts/generate_holidays.py**//
 +<code>
 +#!/usr/bin/env python3
 +
 +import requests
 +import datetime
 +import os
 +import sys
 +
 +DATA_PATH = "../calendar_data"
 +
 +def ordinal(n):
 +    return str(n) + (
 +        "th" if 11 <= n % 100 <= 13 else
 +        {1: "st", 2: "nd", 3: "rd"}.get(n % 10, "th")
 +    )
 +
 +def generate(year, country="US"):
 +    os.makedirs(DATA_PATH, exist_ok=True)
 +
 +    url = f"https://date.nager.at/api/v3/PublicHolidays/{year}/{country}"
 +    r = requests.get(url)
 +    holidays = r.json()
 +
 +    filename = os.path.join(DATA_PATH, f"cal.{year}")
 +
 +    with open(filename, "w") as f:
 +        for h in holidays:
 +            d = datetime.datetime.strptime(h["date"], "%Y-%m-%d")
 +            mmdd = d.strftime("%m%d")
 +            f.write(f"{mmdd} {ordinal(d.day):<5}- {h['localName']}\n")
 +
 +    print(f"Generated {filename}")
 +
 +if __name__ == "__main__":
 +    year = int(sys.argv[1]) if len(sys.argv) > 1 else datetime.date.today().year + 1
 +    generate(year)
 </code> </code>
mystic_cal/mystic_cal_code.1771259575.txt.gz · Last modified: by freedomotter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki