diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5172429 Binary files /dev/null and b/.DS_Store differ diff --git a/src/server/app.py b/src/server/app.py index fd300f8..6ccac4c 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -20,7 +20,7 @@ def get_initial_posts(): # Use archive parser to fetch posts posts = archive_parser.get_posts(count=10, start_index=0) return jsonify(posts) - except Exception as e: + except Exception: return jsonify({"error": "Failed to fetch posts"}), 500 @@ -35,7 +35,7 @@ def get_more_posts(): posts = archive_parser.get_posts(count=10, start_index=count) return jsonify(posts) - except Exception as e: + except Exception: return jsonify({"error": "Failed to fetch more posts"}), 500 @@ -46,7 +46,7 @@ def get_total_posts(): # Get total from archive parser total = archive_parser.get_total_posts() return jsonify({"total": total}) - except Exception: + except Exception as e: return jsonify({"error": "Failed to fetch total count"}), 500 diff --git a/src/server/parse_archive.py b/src/server/parse_archive.py index 218d4e2..b0f4fd0 100644 --- a/src/server/parse_archive.py +++ b/src/server/parse_archive.py @@ -2,6 +2,7 @@ import os import subprocess import json from typing import List, Dict, Any +import uuid class ArchiveParser: @@ -44,7 +45,9 @@ class ArchiveParser: dir_path = os.path.join(self.archive_dir, directory) posts.extend(self._extract_posts_from_directory(dir_path)) - return posts + # Convert extracted posts to final format with proper IDs + formatted_posts = [self._create_post(post) for post in posts] + return formatted_posts except subprocess.CalledProcessError as e: print(f"Error executing command: {e}") @@ -110,3 +113,25 @@ class ArchiveParser: except Exception as e: print(f"Error getting total posts: {e}") return 0 + + def _create_post(self, index) -> Dict[str, Any]: + """Convert an index entry to a properly formatted post with ID and default image.""" + try: + post = dict() + + # Ensure we have all required fields with defaults + post["id"] = str(uuid.uuid4()) # Generate a unique ID for each post + post["title"] = index.get("title", "Untitled Post") + post["url"] = index.get("url", "#") + + # Set default image to reddit_logo.webp if no image is provided + post["image"] = ( + "/Reddit_Logo.webp" # Default to the logo in website directory + ) + + return post + + except Exception as e: + print(f"Error converting index to post: {e}") + # Return a minimal post if there's an error + raise e diff --git a/src/server/parse_archive_fixed.py b/src/server/parse_archive_fixed.py new file mode 100644 index 0000000..e69de29 diff --git a/src/website/Reddit_Logo.webp b/src/website/Reddit_Logo.webp new file mode 100644 index 0000000..faed017 Binary files /dev/null and b/src/website/Reddit_Logo.webp differ