mystic_cal:mystic_cal_code
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| mystic_cal:mystic_cal_code [2026/02/16 16:32] – created freedomotter | mystic_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:** | ||
| + | < | ||
| + | Editors → Scripts → Add | ||
| + | </ | ||
| + | |||
| + | **Command: | ||
| + | < | ||
| + | python3 scripts/ | ||
| + | </ | ||
| + | |||
| + | **Birthday mode:** | ||
| + | < | ||
| + | python3 scripts/ | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== Main Calendar Script ===== | ||
| + | |||
| + | // | ||
| < | < | ||
| # | # | ||
| Line 102: | Line 128: | ||
| main() | main() | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Birthday Generator ===== | ||
| + | |||
| + | // | ||
| + | < | ||
| + | # | ||
| + | |||
| + | import os | ||
| + | import datetime | ||
| + | import mystic | ||
| + | |||
| + | DATA_PATH = " | ||
| + | |||
| + | def ordinal(n): | ||
| + | return str(n) + ( | ||
| + | " | ||
| + | {1: " | ||
| + | ) | ||
| + | |||
| + | def generate(year): | ||
| + | os.makedirs(DATA_PATH, | ||
| + | filename = os.path.join(DATA_PATH, | ||
| + | |||
| + | users = mystic.user_list() | ||
| + | |||
| + | entries = [] | ||
| + | |||
| + | for u in users: | ||
| + | if not u.birthdate: | ||
| + | continue | ||
| + | |||
| + | bd = datetime.datetime.strptime(u.birthdate, | ||
| + | mmdd = bd.strftime(" | ||
| + | |||
| + | line = f" | ||
| + | entries.append(line) | ||
| + | |||
| + | entries.sort() | ||
| + | |||
| + | with open(filename, | ||
| + | for e in entries: | ||
| + | f.write(e + " | ||
| + | |||
| + | print(f" | ||
| + | |||
| + | |||
| + | if __name__ == " | ||
| + | year = datetime.date.today().year | ||
| + | generate(year) | ||
| + | generate(year + 1) | ||
| + | </ | ||
| + | |||
| + | ===== Holiday Generator ===== | ||
| + | **Install requirements: | ||
| + | < | ||
| + | pip3 install requests | ||
| + | </ | ||
| + | |||
| + | // | ||
| + | < | ||
| + | # | ||
| + | |||
| + | import requests | ||
| + | import datetime | ||
| + | import os | ||
| + | import sys | ||
| + | |||
| + | DATA_PATH = " | ||
| + | |||
| + | def ordinal(n): | ||
| + | return str(n) + ( | ||
| + | " | ||
| + | {1: " | ||
| + | ) | ||
| + | |||
| + | def generate(year, | ||
| + | os.makedirs(DATA_PATH, | ||
| + | |||
| + | url = f" | ||
| + | r = requests.get(url) | ||
| + | holidays = r.json() | ||
| + | |||
| + | filename = os.path.join(DATA_PATH, | ||
| + | |||
| + | with open(filename, | ||
| + | for h in holidays: | ||
| + | d = datetime.datetime.strptime(h[" | ||
| + | mmdd = d.strftime(" | ||
| + | f.write(f" | ||
| + | |||
| + | print(f" | ||
| + | |||
| + | if __name__ == " | ||
| + | year = int(sys.argv[1]) if len(sys.argv) > 1 else datetime.date.today().year + 1 | ||
| + | generate(year) | ||
| </ | </ | ||
mystic_cal/mystic_cal_code.1771259575.txt.gz · Last modified: by freedomotter
