Add website publishing functionality for meals page#51
Conversation
After sending the email, the script now also generates a meals.html page for the website repo, commits it, and pushes. Sends an error email to SENDER if the website publish fails. Set WEBSITE_REPO_PATH in .env to enable. https://claude.ai/code/session_01Nu5ZtcnzQjFsMdYaa7gtpF
Reviewer's GuideImplements website publishing for the weekly meals email by returning the generated HTML from the email workflow, wrapping it in a website-specific template inside a new website repository, and committing/pushing the resulting meals.html file, with integrated error handling and configuration via WEBSITE_REPO_PATH. Sequence diagram for meals email generation and website publishingsequenceDiagram
actor User
participant Main as Main
participant EmailGenerator as generate_html_email
participant Mailer as send_email
participant WebsitePublisher as publish_meals_page
participant ErrorNotifier as _send_error_notification
participant Git as git_remote_repo
User->>Main: main(debug_mode=False)
Main->>Main: _select_and_prepare_meals
Main->>Main: _generate_and_send_email
activate Main
Main->>EmailGenerator: generate_html_email(context, meals)
EmailGenerator-->>Main: html_content
Main->>Mailer: send_email(html_content, debug_mode, SUBJECT)
Mailer-->>Main: ok
Main-->>Main: return html_content
deactivate Main
Main->>Main: _publish_meals_to_website(html_content)
alt WEBSITE_REPO_PATH not set
Main-->>Main: log warning and skip publish
else WEBSITE_REPO_PATH set
Main->>WebsitePublisher: publish_meals_page(html_content, WEBSITE_REPO_PATH)
activate WebsitePublisher
WebsitePublisher->>WebsitePublisher: generate_meals_page_html
WebsitePublisher->>Git: git add/commit/push meals.html
Git-->>WebsitePublisher: success
WebsitePublisher-->>Main: ok
deactivate WebsitePublisher
end
Main->>Main: _update_tracking_data
rect rgb(255,230,230)
Main->>WebsitePublisher: publish_meals_page
WebsitePublisher-->>Main: exception e
Main->>ErrorNotifier: _send_error_notification(e, subject)
ErrorNotifier->>Mailer: send_email(error_html, debug_mode=True, subject)
Mailer-->>ErrorNotifier: ok
end
Class diagram for main workflow and website_publisher functionsclassDiagram
class MainModule {
+main() void
+_generate_and_send_email(context: dict~str, Any~, meals: list~dict~str, Any~~, start_time: float, debug_mode: bool) str
+_publish_meals_to_website(html_content: str) void
+_send_error_notification(error: Exception, subject: str = Recipe Emailer Error) void
+_update_tracking_data(context: dict~str, Any~, meals: list~dict~str, Any~~) void
}
class WebsitePublisherModule {
+publish_meals_page(email_html: str, website_repo_path: str) void
+generate_meals_page_html(email_html: str, website_repo_path: str) str
+_git_commit_and_push(repo_path: str) void
}
class ConfigModule {
<<module>>
+WEBSITE_REPO_PATH: str | None
}
MainModule --> WebsitePublisherModule : calls publish_meals_page
MainModule --> ConfigModule : reads WEBSITE_REPO_PATH
MainModule --> MainModule : calls _send_error_notification on errors
WebsitePublisherModule --> WebsitePublisherModule : calls _git_commit_and_push internally
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
generate_meals_page_html, relying onemail_html.index('<body>')/index('</body>')will raise aValueErrorif the expected tags are missing or differently cased; consider using a more robust approach (e.g.,.findwith explicit error handling or an HTML parser) so website publishing fails with a clearer, controlled error. - When reading
navbar.htmland writingmeals.html, it might be worth validating thatwebsite_repo_pathandtemplates/navbar.htmlactually exist and logging a clear, specific error if they do not, rather than relying on generic file I/O exceptions from theopencall. - In
_git_commit_and_push, failures from thegitcommands are surfaced only as genericCalledProcessError; wrapping therun_gitcalls in try/except and logging the underlyingstderrwould make diagnosing publish failures significantly easier.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `generate_meals_page_html`, relying on `email_html.index('<body>')` / `index('</body>')` will raise a `ValueError` if the expected tags are missing or differently cased; consider using a more robust approach (e.g., `.find` with explicit error handling or an HTML parser) so website publishing fails with a clearer, controlled error.
- When reading `navbar.html` and writing `meals.html`, it might be worth validating that `website_repo_path` and `templates/navbar.html` actually exist and logging a clear, specific error if they do not, rather than relying on generic file I/O exceptions from the `open` call.
- In `_git_commit_and_push`, failures from the `git` commands are surfaced only as generic `CalledProcessError`; wrapping the `run_git` calls in try/except and logging the underlying `stderr` would make diagnosing publish failures significantly easier.
## Individual Comments
### Comment 1
<location> `website_publisher.py:34-35` </location>
<code_context>
+def generate_meals_page_html(email_html: str, website_repo_path: str) -> str:
+ """Generate a website-compatible meals.html page from email HTML content."""
+ # Extract recipe card content from email HTML body
+ body_start = email_html.index("<body>") + len("<body>")
+ body_end = email_html.index("</body>")
+ recipe_content = email_html[body_start:body_end].strip()
+
</code_context>
<issue_to_address>
**issue:** Using `str.index` on `<body>`/`</body>` assumes the exact tags always exist and will raise unhandled `ValueError` otherwise.
This relies on the HTML containing a single lowercase `<body>`/`</body>` pair with no attributes. If the template changes (e.g., different casing, attributes on `<body>`, or partial HTML), `index` will raise `ValueError` and break the publish step. Consider a more robust approach (e.g., a lightweight HTML parser), or at least use `str.find` plus explicit error handling/logging so failures are handled predictably.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| body_start = email_html.index("<body>") + len("<body>") | ||
| body_end = email_html.index("</body>") |
There was a problem hiding this comment.
issue: Using str.index on <body>/</body> assumes the exact tags always exist and will raise unhandled ValueError otherwise.
This relies on the HTML containing a single lowercase <body>/</body> pair with no attributes. If the template changes (e.g., different casing, attributes on <body>, or partial HTML), index will raise ValueError and break the publish step. Consider a more robust approach (e.g., a lightweight HTML parser), or at least use str.find plus explicit error handling/logging so failures are handled predictably.
|
✅ All CI checks passed! Ready for review. |
Description
This PR adds functionality to automatically publish the weekly meals page to a website repository. After generating and sending the weekly meals email, the system now wraps the email HTML content in a website template and commits/pushes it to a configured website repository.
Type of Change
Motivation and Context
The meals email content should be published to a website for broader accessibility. This change integrates website publishing into the existing recipe emailer workflow, allowing the same meal data to be distributed via both email and web.
Changes Made
Code Changes
New file:
website_publisher.pypublish_meals_page(): Main function that wraps email HTML in website template and commits/pushes to repogenerate_meals_page_html(): Generates a complete HTML page from email content, including navbar template and styled meal cards_git_commit_and_push(): Handles git operations (add, commit, push) with proper error handlingModified:
main.py_generate_and_send_email()to return HTML content for reuse_publish_meals_to_website()wrapper function that handles publishing with error notification on failure_send_error_notification()to accept custom subject line for different error typespublish_meals_pageandWEBSITE_REPO_PATHModified:
config.pyWEBSITE_REPO_PATHenvironment variable configuration__all__exports for public APIConfiguration Changes
WEBSITE_REPO_PATH- path to website repository for publishing meals pageTesting
The changes integrate with existing error handling and logging infrastructure. Website publishing is:
-dflag behavior)WEBSITE_REPO_PATHis not configuredCode Quality Checklist
WEBSITE_REPO_PATHnot setSecurity Considerations
Deployment Notes
Pre-deployment:
WEBSITE_REPO_PATHenvironment variable to website repository path (optional)Deployment steps:
WEBSITE_REPO_PATHenvironment variableRollback plan:
WEBSITE_REPO_PATHenvironment variable to disable website publishingRelated PRs/Issues
https://claude.ai/code/session_01Nu5ZtcnzQjFsMdYaa7gtpF
Summary by Sourcery
Integrate website publishing of the weekly meals content into the existing recipe emailer workflow.
New Features:
Enhancements: