headlines-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/bin/headlines.js +55 -0
- package/index.js +26 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# headlines-cli
|
|
2
|
+
|
|
3
|
+
Fetch news headlines from **HackerNews, Reddit, and RSS feeds** with zero API keys.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g headlines-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### HackerNews
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
headlines hn 15 # Top 15 HN stories
|
|
17
|
+
headlines hn # Top 10 (default)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Reddit
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
headlines reddit programming 20 # r/programming, 20 posts
|
|
24
|
+
headlines reddit nodejs # r/nodejs, 10 posts (default)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API Usage
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
const { getHNStories, getRedditPosts } = require('headlines-cli');
|
|
31
|
+
|
|
32
|
+
const stories = await getHNStories(10);
|
|
33
|
+
const posts = await getRedditPosts('programming', 15);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- ā
No API key required
|
|
39
|
+
- ā
Multiple sources (HN, Reddit)
|
|
40
|
+
- ā
Zero dependencies (besides CLI helpers)
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
package/bin/headlines.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
|
|
6
|
+
program
|
|
7
|
+
.name('headlines')
|
|
8
|
+
.description('Fetch news headlines from HackerNews, Reddit, RSS feeds')
|
|
9
|
+
.version('1.0.0');
|
|
10
|
+
|
|
11
|
+
program
|
|
12
|
+
.command('hn [limit]')
|
|
13
|
+
.description('Top stories from HackerNews')
|
|
14
|
+
.action(async (limit = 10) => {
|
|
15
|
+
try {
|
|
16
|
+
const res = await fetch('https://hacker-news.firebaseio.com/v0/topstories.json');
|
|
17
|
+
const ids = (await res.json()).slice(0, limit);
|
|
18
|
+
|
|
19
|
+
console.log(chalk.cyan('\nš° HackerNews Top Stories\n'));
|
|
20
|
+
|
|
21
|
+
for (const id of ids) {
|
|
22
|
+
const item = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`).then(r => r.json());
|
|
23
|
+
console.log(`${chalk.yellow(item.title)}`);
|
|
24
|
+
console.log(`${chalk.gray(' ā ' + (item.score || 0) + ' | ' + item.url)}\n`);
|
|
25
|
+
}
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.log(chalk.red(`Error: ${err.message}`));
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
program
|
|
33
|
+
.command('reddit [subreddit] [limit]')
|
|
34
|
+
.description('Hot posts from a subreddit')
|
|
35
|
+
.action(async (subreddit = 'programming', limit = 10) => {
|
|
36
|
+
try {
|
|
37
|
+
const res = await fetch(`https://www.reddit.com/r/${subreddit}/hot.json?limit=${limit}`, {
|
|
38
|
+
headers: { 'User-Agent': 'headlines-cli' }
|
|
39
|
+
});
|
|
40
|
+
const data = await res.json();
|
|
41
|
+
|
|
42
|
+
console.log(chalk.cyan(`\nš„ r/${subreddit} Hot\n`));
|
|
43
|
+
|
|
44
|
+
data.data.children.slice(0, limit).forEach(post => {
|
|
45
|
+
const p = post.data;
|
|
46
|
+
console.log(`${chalk.yellow(p.title)}`);
|
|
47
|
+
console.log(`${chalk.gray(' ā ' + p.ups + ' | ' + (p.url || 'text post'))}\n`);
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.log(chalk.red(`Error: ${err.message}`));
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
program.parse(process.argv);
|
package/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
async function getHNStories(limit = 10) {
|
|
2
|
+
const res = await fetch('https://hacker-news.firebaseio.com/v0/topstories.json');
|
|
3
|
+
const ids = (await res.json()).slice(0, limit);
|
|
4
|
+
|
|
5
|
+
const stories = [];
|
|
6
|
+
for (const id of ids) {
|
|
7
|
+
const item = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`).then(r => r.json());
|
|
8
|
+
stories.push({ title: item.title, url: item.url, score: item.score });
|
|
9
|
+
}
|
|
10
|
+
return stories;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function getRedditPosts(subreddit = 'programming', limit = 10) {
|
|
14
|
+
const res = await fetch(`https://www.reddit.com/r/${subreddit}/hot.json?limit=${limit}`, {
|
|
15
|
+
headers: { 'User-Agent': 'headlines-cli' }
|
|
16
|
+
});
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
|
|
19
|
+
return data.data.children.slice(0, limit).map(p => ({
|
|
20
|
+
title: p.data.title,
|
|
21
|
+
upvotes: p.data.ups,
|
|
22
|
+
url: p.data.url
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = { getHNStories, getRedditPosts };
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "headlines-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Fetch news headlines from free sources (HN, Reddit, RSS) with zero API keys",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"headlines": "bin/headlines.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo 'No tests yet'"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"news",
|
|
14
|
+
"headlines",
|
|
15
|
+
"hackernews",
|
|
16
|
+
"reddit",
|
|
17
|
+
"rss",
|
|
18
|
+
"cli"
|
|
19
|
+
],
|
|
20
|
+
"author": "Bagalobsta <bagalobsta@protonmail.com>",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/bagalobsta/bagalobsta-skills.git"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"chalk": "^4.1.2",
|
|
28
|
+
"commander": "^11.1.0"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=14.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|