Reorganize codebase: separate server architecture from business logic
- Created feed_parser.py module with YouTubeFeedParser and FeedEntry classes - Refactored main.py to focus on Flask routing with two endpoints: - GET / for homepage - GET /api/feed for REST API with query parameters - Updated CLAUDE.md with new architecture documentation - Implemented clean separation between core logic and web server layers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
60
main.py
Normal file
60
main.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""Flask web application for YouTube RSS feed parsing."""
|
||||
|
||||
from flask import Flask, render_template, request, jsonify
|
||||
from feed_parser import YouTubeFeedParser
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Default channel ID for demonstration
|
||||
DEFAULT_CHANNEL_ID = "UCtTWOND3uyl4tVc_FarDmpw"
|
||||
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
def index():
|
||||
"""Render the main page."""
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@app.route("/api/feed", methods=["GET"])
|
||||
def get_feed():
|
||||
"""API endpoint to fetch YouTube channel feed.
|
||||
|
||||
Query parameters:
|
||||
channel_id: YouTube channel ID (optional, uses default if not provided)
|
||||
filter_shorts: Whether to filter out Shorts (default: true)
|
||||
|
||||
Returns:
|
||||
JSON response with feed data or error message
|
||||
"""
|
||||
channel_id = request.args.get("channel_id", DEFAULT_CHANNEL_ID)
|
||||
filter_shorts = request.args.get("filter_shorts", "true").lower() == "true"
|
||||
|
||||
parser = YouTubeFeedParser(channel_id)
|
||||
result = parser.fetch_feed(filter_shorts=filter_shorts)
|
||||
|
||||
if result is None:
|
||||
return jsonify({"error": "Failed to fetch feed"}), 500
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
def main():
|
||||
"""CLI entry point for testing feed parser."""
|
||||
parser = YouTubeFeedParser(DEFAULT_CHANNEL_ID)
|
||||
result = parser.fetch_feed()
|
||||
|
||||
if result is None:
|
||||
print("Failed to retrieve RSS feed")
|
||||
return
|
||||
|
||||
print(f"Feed Title: {result['feed_title']}")
|
||||
print(f"Feed Link: {result['feed_link']}")
|
||||
|
||||
for entry in result['entries']:
|
||||
print(f"\nEntry Title: {entry['title']}")
|
||||
print(f"Entry Link: {entry['link']}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user