Fetch Hacker News top stories right from your terminal.
- Verify you have Python 3 installed:
$ python3 --version- If not installed, download Python here
Clone this repository to your machine. Then create a python virtual environment as follows:
-
On your terminal, navigate to the repository's root directory and create a venv (recommended):
python3 -m venv <venv_name>
where <venv_name> is the name you want to give the virtual environment
-
To activate the environment:
On MacOS/Linux execute:
source <venv_name>/bin/activate
On Windows execute:
.\<venv_name>\Scripts\activate
-
With the virtual environment active, install the required libraries with pip:
pip3 install -r ./requirements.txt
-
Execute the program:
$ python3 hnreader.pyThis will fetch the latest top 10 stories.
- You can specify the number of stories to fetch with the
-qor--quantityflag:
$ python3 hnreader.py -q 25This will fetch the latest top 25 stories
- Depending on your terminal: Ctr+click, Cmd+click, or just click on the link in the story to open it in a browser.
- If using zsh on macOS, you can preview the story without opening a browser:
- Ctrl+click on the url, then select "Quick Look"
- If using zsh on macOS, you can preview the story without opening a browser:
Note: The max number of stories is 500 per the Hacker News API limit.
- Launch interactive TUI mode:
$ python3 hnreader.py -tUse Up/Down arrows to move between stories, then press Enter to open the selected story in your browser.
- Alternatively, you can run the file directly from the root directory (no venv):
$ python3 hnreader.py$ python3 hnreader.py -h
usage: hnreader [-h] [-q] [-t]
Fetch the latest top stories from Hacker News
optional arguments:
-h, --help show this help message and exit
-q , --quantity The number of stories to display (max is 500). If not provided, the default is 10.
-t, --tui Launch interactive TUI mode.
$ python3 hnreader.py -q 5
******************************************************************
Hacker News - Top Stories
Fri Feb 10 10:47:44 2023
******************************************************************
[fetching the latest top 5 stories...]
[1]. “Open Source” Seeds Loosen Big Ag’s Grip on Farmers
https://worldsensorium.com/open-source-seeds-loosen-big-ags-grip-on-farmers/
207 points | 2 hours ago
-------------------------
[2]. Is Seattle a 15-minute city? It depends on where you want to walk
https://nathenry.com/writing/2023-02-07-seattle-walkability.html
102 points | 1 hour ago
-------------------------
[3]. Show HN: Spaghettify – A VSCode Extension to make your code worse with AI
https://www.spaghettify.dev/
74 points | 1 hour ago
-------------------------
[4]. Manticore 6.0.0 – a faster alternative to Elasticsearch in C++
https://manticoresearch.com/blog/manticore-search-6-0-0/
47 points | 1 hour ago
-------------------------
[5]. Show HN: Dslcad a programming language and interpreter for building 3D models
https://github.com/DSchroer/dslcad
53 points | 1 hour ago
-------------------------
