A simple and elegant way to view the top stories from Hacker News. This project fetches the latest top stories from Hacker News and displays them in a clean, responsive HTML page.
- Fetches top 30 stories from Hacker News
- Clean, modern UI with responsive design
- Shows story title, points, author, and timestamp
- Direct links to original stories
- Hover effects for better interaction
- Mobile-friendly layout
- Python 3.x
requests
library
- Clone the repository:
git clone https://github.com/ashkan-deriv/top-stories-on-hacker-news.git
cd top-stories-on-hacker-news
- Install the required package:
pip install requests
- Run the Python script:
python3 hn_stories.py
-
The script will:
- Fetch the latest top stories from Hacker News
- Generate an HTML file named
hn_stories.html
- Print a confirmation message when done
-
Open
hn_stories.html
in your web browser to view the stories
The project consists of two main components:
-
hn_stories.py
: Python script that:- Fetches data from the Hacker News API
- Processes the story information
- Generates a styled HTML page
-
Generated
hn_stories.html
: A responsive webpage that:- Displays stories in a clean card layout
- Shows points, author, and timestamp for each story
- Provides clickable links to original stories
- Uses modern CSS styling with hover effects
You can modify the following aspects:
- Number of stories: Change the slice index in
story_ids = requests.get(top_stories_url).json()[:30]
- Styling: Modify the CSS in the
generate_html()
function - Display format: Adjust the HTML template in the same function
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is open source and available under the MIT License.