Initial commit

This commit is contained in:
2025-11-11 00:05:03 -08:00
commit 29bb077980
2 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import argparse
import mailbox
import json
import re
from pathlib import Path
parser = argparse.ArgumentParser(description="Tallies up the number of McDonald's coupons used by scanning a local email inbox.")
parser.add_argument('mailbox_path', help="Path of the mailbox file containing McDonald's coupons, i.e. '~/.thunderbird/abc123.default-release/Mail/Local Folders/McDonalds'")
args = parser.parse_args()
# Load coupon strings from JSON
with open('coupon_names.json') as f:
coupons = json.load(f)
# Initialize counts with compiled regex patterns
coupon_patterns = {p: re.compile(re.escape(p), re.IGNORECASE) for p in coupons}
counts = {p: 0 for p in coupons}
# Thunderbird mailbox location (update if different)
mbox_path = Path(args.mailbox_path)
if not mbox_path.exists():
raise FileNotFoundError(f"Mailbox not found at {args.mailbox_path}")
# Process mailbox
mbox = mailbox.mbox(mbox_path)
for message in mbox:
# Extract text content from all parts
body = []
if message.is_multipart():
for part in message.walk():
content_type = part.get_content_type()
if content_type == 'text/plain':
payload = part.get_payload(decode=True)
try:
body.append(payload.decode('utf-8'))
except UnicodeDecodeError:
body.append(payload.decode('latin-1'))
else:
payload = message.get_payload(decode=True)
try:
body = [payload.decode('utf-8')]
except UnicodeDecodeError:
body = [payload.decode('latin-1')]
# Check each coupon pattern against full body text
full_text = ' '.join(body)
for coupon, pattern in coupon_patterns.items():
if pattern.search(full_text):
counts[coupon] += 1
# Display results
print("McDonald's Coupon Counts:")
for coupon, count in counts.items():
print(f"{coupon:<75}\t\t{count}")

10
coupon_names.json Normal file
View File

@@ -0,0 +1,10 @@
[
"FREE 4pc Chicken McNuggets® or Snack Wrap®, no purchase necessary",
"FREE Apple Pie or Small Fries, no purchase necessary",
"FREE Small Premium Roast Coffee or Small Soft Drink, no purchase necessary",
"FREE Double Cheeseburger or McChicken®, no purchase necessary",
"FREE Any Biscuit Breakfast Sandwich, no purchase necessary",
"FREE Small McCafé® Frappé, Shake or Smoothie, no purchase necessary",
"FREE 2 Chocolate Chip Cookies or Mini McFlurry®, no purchase necessary",
"FREE Small Fries or Vanilla Cone, no purchase necessary"
]