Skip to content

ilyaizen/hn-clone

Repository files navigation

Yet Another Hacker News Clone

YAHNC is a FastAPI-based web application that fetches and displays top stories from Hacker News with additional features like trend indicators when a story is trending and images fetched from Open Graph metadata.

Features

  • Fetches top 30 stories from Hacker News API
  • Displays stories with images, descriptions, and metadata
  • Shows trending information for trending stories
  • Dark mode toggle
  • Responsive design using Tailwind CSS
  • Automatic page refresh every 15 minutes

Tech Stack

  • Backend: Python 3.10+, FastAPI, SQLAlchemy, aiohttp
  • Frontend: HTML, Tailwind CSS, JavaScript
  • Database: SQLite (with aiosqlite for async operations)
  • Other: BeautifulSoup4, Pillow

Setup and Installation

  1. Clone the repository:

    git clone https://github.com/ilyaizen/hn-clone.git
    cd hn-clone
  2. Create a virtual environment and activate it:

    python -m venv .venv
    source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`
  3. Install the required packages:

    pip install -r requirements.txt
  4. Run the application:

    uvicorn main:app --reload
  5. Open your browser and navigate to http://localhost:8000

Project Structure

  • main.py: FastAPI application and main route
  • hn_scraper.py: Hacker News API scraper
  • database.py: Database operations and ORM setup
  • metadata.py: Metadata fetching and image processing
  • models.py: SQLAlchemy models
  • templates/: HTML templates
  • static/: Static files (CSS, images)
  • install-service.ps1: PowerShell script to install YAHNC as a Windows service
  • remove-service.ps1: PowerShell script to remove the YAHNC Windows service

Running as a Windows Service

You can run YAHNC as a Windows service, which allows it to start automatically when your computer boots and handle system sleep/wake cycles.

Prerequisites

  1. Install NSSM (Non-Sucking Service Manager):
    • Download from NSSM website
    • Extract and place nssm.exe in "C:\Program Files\nssm" (create this directory if it doesn't exist)

Installing the Service

  1. Open PowerShell as Administrator

  2. Navigate to the project directory

  3. Run the installation script:

    .\install-service.ps1

This script will:

  • Create a Python virtual environment if it doesn't exist
  • Install required dependencies
  • Configure YAHNC as a Windows service that starts automatically
  • Set up the service to handle system sleep/wake cycles
  • Start the service

Once installed, YAHNC will be accessible at http://localhost:80

Removing the Service

  1. Open PowerShell as Administrator

  2. Navigate to the project directory

  3. Run the removal script:

    .\remove-service.ps1

This script will:

  • Stop the YAHNC service if it's running
  • Completely remove the service from your system

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.