Build an AI Content Factory · 30 min · Python · Notion API (notion-client)
Output Destination & Automation
Six great pieces of content sitting in a terminal you'll never scroll back to isn't a content factory -- it's a script that ran once.
Hiring signal: Wiring a working pipeline to a real, persistent destination and a simple CLI trigger is what turns a one-off script into something you'd actually run again next week.
What you will learn
- Save pipeline outputs to a Notion database, with a local-file fallback
- Build a CLI entry point that runs the full pipeline from a single command
- Run the finished factory end to end on 3 different real inputs
What You're Building
Everything from Lessons 1-4 wired into one CLI command: python factory.py "<url-or-video-or-text>" runs the whole pipeline and saves all 6 outputs somewhere durable. Today's lesson is the last piece before this is genuinely a tool you'd use again next week instead of a script you ran once for this course.
Notion as the output destination
from notion_client import Client
notion = Client(auth=os.environ["NOTION_API_KEY"])
def save_to_notion(database_id: str, source: str, results: dict):
for platform, result in results.items():
if result["status"] != "ok":
continue
notion.pages.create(
parent={"database_id": database_id},
properties={
"Name": {"title": [{"text": {"content": f"{platform} - {source[:50]}"}}]},
"Platform": {"select": {"name": platform}},
},
children=[{
"object": "block", "type": "paragraph",
"paragraph": {"rich_text": [{"text": {"content": result["content"][:2000]}}]},
}],
)
Note the if result["status"] != "ok": continue -- this is Lesson 4's failed-vs-succeeded distinction paying off directly: you never silently write a failed generator's error message into Notion as if it were real content. Also note the [:2000] truncation -- Notion's rich_text blocks have their own length limits per block, which is exactly the kind of platform-specific constraint (like Lesson 3's tweet-length enforcement) that's easy to discover the hard way if you don't check for it up front.
Not everyone wants a Notion account for a course lab
Build a local-markdown fallback too: if NOTION_API_KEY isn't set, write each result to output/{platform}_{timestamp}.md instead. This isn't extra scope for its own sake -- it's the same "handle the realistic failure case" instinct from Lesson 2's preprocessors, applied to the output side: don't make the whole pipeline unusable because of one missing API key.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers The CLI entry point: the whole pipeline, one command, Ship it — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy