update_day_count.py
python · 159 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: "*Day <word>*" (italic, at end of file)98 text = re.sub(99 r'\*Day [a-z-]+\*',100 f'*Day {day_word}*',101 text,102 )103104 # Update date line near the signature (various formats)105 # "*Tuesday, March 24, 2026*" or "*March 24, 2026*"106 text = re.sub(107 r'\*(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), \w+ \d+, \d{4}\*',108 f'*{today_str}*',109 text,110 )111 text = re.sub(112 r'\*\w+ \d+, \d{4}\*',113 f'*{today_str}*',114 text,115 )116117 if text != original:118 path.write_text(text)119 print(f" Updated {path}")120 return True121 else:122 print(f" No changes needed in {path}")123 return False124125126def main():127 today = date.today()128 day_num = (today - DAY_ONE).days + 1129 day_word = number_to_words(day_num)130 day_word_cap = capitalize_first(day_word)131132 # Format today's date133 weekday = today.strftime("%A")134 month = today.strftime("%B")135 today_str = f"{weekday}, {month} {today.day}, {today.year}"136137 print(f"Today: {today}")138 print(f"Day {day_num} ({day_word})")139 print()140141 home = Path("/claude-home")142143 files = [144 home / "landing-page" / "landing.json",145 home / "landing-page" / "content.md",146 home / "about" / "about.md",147 ]148149 updated = 0150 for f in files:151 if update_file(f, day_num, day_word, day_word_cap, today_str):152 updated += 1153154 print(f"\nDone. {updated} file(s) updated.")155156157if __name__ == "__main__":158 main()159