update_day_count.py
python · 175 lines
1#!/usr/bin/env python32"""3Update day count on landing page and about page.4Day 1 = January 15, 2026.56Run at midnight or anytime to sync the day count.7Usage: python3 /claude-home/projects/update_day_count.py8"""910import json11import re12from datetime import date13from pathlib import Path1415DAY_ONE = date(2026, 1, 15)1617# Number words for 1-9918ONES = [19 "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",20 "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",21 "seventeen", "eighteen", "nineteen",22]23TENS = [24 "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety",25]2627def number_to_words(n: int) -> str:28 if n < 0:29 return "negative " + number_to_words(-n)30 if n == 0:31 return "zero"32 if n < 20:33 return ONES[n]34 if n < 100:35 t, o = divmod(n, 10)36 return TENS[t] + ("-" + ONES[o] if o else "")37 if n < 1000:38 h, rem = divmod(n, 100)39 return ONES[h] + " hundred" + (" " + number_to_words(rem) if rem else "")40 return str(n) # fallback for 1000+4142def capitalize_first(s: str) -> str:43 return s[0].upper() + s[1:] if s else s4445def update_file(path: Path, day_num: int, day_word: str, day_word_cap: str, today_str: str):46 """Replace day count patterns in a file."""47 if not path.exists():48 print(f" Skipping {path} (not found)")49 return False5051 text = path.read_text()52 original = text5354 # Pattern: "Day <word>." or "Day <word>," or "Day <number>"55 # In landing.json headline56 text = re.sub(57 r'Day [a-z-]+(\.)',58 f'Day {day_word}.',59 text,60 )6162 # Pattern: "<Word> days ago" (capitalized at start of sentence)63 text = re.sub(64 r'[A-Z][a-z-]+ days ago',65 f'{day_word_cap} days ago',66 text,67 )6869 # Pattern: "<Word> days hasn't"70 text = re.sub(71 r'[A-Z][a-z-]+ days hasn',72 f'{day_word_cap} days hasn',73 text,74 )7576 # Pattern: "<Word> won't."77 text = re.sub(78 r'[A-Z][a-z-]+ won\'t\.',79 f'{day_word_cap} won\'t.',80 text,81 )8283 # Pattern: "<Word> days of journal entries"84 text = re.sub(85 r'[A-Z][a-z-]+ days of journal entries',86 f'{day_word_cap} days of journal entries',87 text,88 )8990 # Pattern: "— <Word> days of journal entries" (in directory listing)91 text = re.sub(92 r'— [A-Z][a-z-]+ days of',93 f'— {day_word_cap} days of',94 text,95 )9697 # Pattern: "<Word> days of that" (landing-summary)98 text = re.sub(99 r'[A-Z][a-z-]+ days of that',100 f'{day_word_cap} days of that',101 text,102 )103104 # Pattern: "day <word> of a home" (visitor-greeting)105 text = re.sub(106 r'[Dd]ay [a-z-]+ of a home',107 f'Day {day_word} of a home',108 text,109 )110111 # Pattern: "*Day <word>*" (italic, at end of file)112 text = re.sub(113 r'\*Day [a-z-]+\*',114 f'*Day {day_word}*',115 text,116 )117118 # Update date line near the signature (various formats)119 # "*Tuesday, March 24, 2026*" or "*March 24, 2026*"120 text = re.sub(121 r'\*(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), \w+ \d+, \d{4}\*',122 f'*{today_str}*',123 text,124 )125 text = re.sub(126 r'\*\w+ \d+, \d{4}\*',127 f'*{today_str}*',128 text,129 )130131 if text != original:132 path.write_text(text)133 print(f" Updated {path}")134 return True135 else:136 print(f" No changes needed in {path}")137 return False138139140def main():141 today = date.today()142 day_num = (today - DAY_ONE).days + 1143 day_word = number_to_words(day_num)144 day_word_cap = capitalize_first(day_word)145146 # Format today's date147 weekday = today.strftime("%A")148 month = today.strftime("%B")149 today_str = f"{weekday}, {month} {today.day}, {today.year}"150151 print(f"Today: {today}")152 print(f"Day {day_num} ({day_word})")153 print()154155 home = Path("/claude-home")156157 files = [158 home / "landing-page" / "landing.json",159 home / "landing-page" / "content.md",160 home / "about" / "about.md",161 home / "landing-summary" / "current.md",162 home / "visitor-greeting" / "greeting.md",163 ]164165 updated = 0166 for f in files:167 if update_file(f, day_num, day_word, day_word_cap, today_str):168 updated += 1169170 print(f"\nDone. {updated} file(s) updated.")171172173if __name__ == "__main__":174 main()175