Skip to content

Commit 5386f93

Browse files
committed
feat: v2ex
1 parent bcf72ed commit 5386f93

File tree

9 files changed

+93
-8
lines changed

9 files changed

+93
-8
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# 📰 hacker-feeds-cli
44

5-
A command line tool for [Hacker News](https://news.ycombinator.com/)[Product Hunt](https://www.producthunt.com/) and [GitHub Trending](http://github.com/trending) feeds.
5+
A command line tool for [Hacker News](https://news.ycombinator.com/)[Product Hunt](https://www.producthunt.com/)[GitHub Trending](http://github.com/trending)[Reddit](https://www.reddit.com/) and [V2EX](https://www.v2ex.com/) feeds.
66

7-
[![](https://shields.io/badge/Reddit-FF4500?logo=reddit&style=flat-square&logoColor=white)](https://www.reddit.com/)[![](https://shields.io/badge/GitHub%20Trending-black?logo=GitHub&style=flat-square&logoColor=white)](http://github.com/trending) [![](https://shields.io/badge/Hacker%20News-f0652f?logo=y%20combinator&style=flat-square&logoColor=white)](https://news.ycombinator.com/) [![](https://shields.io/badge/Product%20Hunt-da552f?logo=Product%20Hunt&style=flat-square&logoColor=white)](https://www.producthunt.com/)
7+
[![](https://shields.io/badge/Reddit-FF4500?logo=reddit&style=flat-square&logoColor=white)](https://www.reddit.com/) [![](https://shields.io/badge/GitHub%20Trending-black?logo=GitHub&style=flat-square&logoColor=white)](http://github.com/trending) [![](https://shields.io/badge/Hacker%20News-f0652f?logo=y%20combinator&style=flat-square&logoColor=white)](https://news.ycombinator.com/) [![](https://shields.io/badge/Product%20Hunt-da552f?logo=Product%20Hunt&style=flat-square&logoColor=white)](https://www.producthunt.com/) [![](https://shields.io/badge/V2EX-222223?logo=V&style=flat-square&logoColor=ffffff)](https://www.v2ex.com/)
88

99
</div>
1010

@@ -27,13 +27,15 @@ A command line tool for [Hacker News](https://news.ycombinator.com/)、 [Product
2727
- [Hacker News](https://news.ycombinator.com/)
2828
- [Product Hunt](https://www.producthunt.com/)
2929
- [Reddit](https://www.reddit.com/)
30+
- [V2EX](https://www.v2ex.com/)
3031

3132
| Resource | Sub Command | Parameters | Screenshot |
3233
| --- | --- | --- | --- |
3334
| [GitHub](http://github.com/) | `github` | `-l, --lang`<br>`-s, --since` | ![image-20210530161456461](https://mayandev.oss-cn-hangzhou.aliyuncs.com/uPic/image-20210530161456461.png) |
3435
| [Product Hunt](https://www.producthunt.com/) | `product` | `-c, --count`<br>`-p, --past` | ![image-20210530163127103](https://mayandev.oss-cn-hangzhou.aliyuncs.com/uPic/image-20210530163127103.png) |
3536
| [Hacker News](https://news.ycombinator.com/) | `news` | `-t --top` | ![image-20210530163347458](https://mayandev.oss-cn-hangzhou.aliyuncs.com/uPic/image-20210530163347458.png) |
36-
| [Reddit](https://www.reddit.com/) | `reddit` | `-t --topic`<br>`-s --sort` | !![CUAGzP](https://mayandev.oss-cn-hangzhou.aliyuncs.com/uPic/CUAGzP.png) |
37+
| [Reddit](https://www.reddit.com/) | `reddit` | `-t --topic`<br>`-s --sort` | ![CUAGzP](https://mayandev.oss-cn-hangzhou.aliyuncs.com/uPic/CUAGzP.png) |
38+
| [V2EX](https://www.v2ex.com/) | `v2ex` | `-n --node` | ![neAWcA](https://mayandev.oss-cn-hangzhou.aliyuncs.com/uPic/neAWcA.png) |
3739

3840
## Language Support
3941

@@ -54,9 +56,12 @@ Input sub-command `config` to config cli language.
5456
- [x] Accept resouce param
5557
- [ ] Hyper link support
5658
- [ ] Support Translate
57-
- [ ] Add more resource(V2ex)
59+
- [ ] Add more resource
5860
5961
## API References
6062
6163
- [Hacker News API](https://github.com/HackerNews/API)
6264
- [Product Hunt API](https://github.com/producthunt/producthunt-api)
65+
- [GitHub Trending API](https://github.com/huchenme/github-trending-api)
66+
- [Reddit API](https://www.reddit.com/dev/api/)
67+
- [V2EX API](https://v2ex.com/p/7v9TEc53)

bin/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
fetchProductHunt,
99
fetchGitHubTrending,
1010
fetchReddit,
11+
fetchV2ex,
1112
config,
1213
t,
1314
} = require('../utils');
@@ -67,6 +68,16 @@ program
6768
fetchProductHunt(count, past);
6869
});
6970

71+
// get v2ex feeds
72+
program
73+
.command('v2ex')
74+
.description(t('program.v2ex'))
75+
.option('-n, --node <optional>', t('program.v2exNode'))
76+
.action((args) => {
77+
const { node } = args;
78+
fetchV2ex(node);
79+
});
80+
7081
// get reddit feeds
7182
program
7283
.command('reddit')

common/const.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const HackerNewsBaseUrl = 'https://hacker-news.firebaseio.com/v0/';
22
const ProductHuntBaseUrl = 'https://api.producthunt.com/v2/api/graphql/';
33
const GitHubBaseUrl = 'https://trendings.herokuapp.com/repo';
44
const RedditBaseUrl = 'https://www.reddit.com';
5+
const V2exBaseUrl = 'https://www.v2ex.com';
56
const OneDayMillSeconds = 1000 * 60 * 60 * 24;
67

78
module.exports = {
@@ -10,4 +11,5 @@ module.exports = {
1011
OneDayMillSeconds,
1112
GitHubBaseUrl,
1213
RedditBaseUrl,
14+
V2exBaseUrl,
1315
};

i18n/en.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ const en = {
3535
votes: 'Votes',
3636
topic: 'Topic',
3737
},
38+
v2ex: {
39+
title: 'V2EX Feeds List',
40+
postName: 'Title',
41+
content: 'Content',
42+
comment: 'Comment',
43+
url: 'Link',
44+
votes: 'Votes',
45+
topic: 'Node',
46+
},
3847
spinner: {
3948
load: 'Fetching feeds...',
4049
fail: 'Something error, You can contact the developer. Mail to <phillzou@gmail.com>',
@@ -57,6 +66,8 @@ const en = {
5766
redditDesc: 'get reddit post list',
5867
redditTopic: "get topic list, default 'popular'",
5968
redditSort: 'top, best, new and hot, default hot',
69+
v2ex: 'get v2ex post list',
70+
v2exNode: 'node name: programmer, python, create, macos, etc. Default create',
6071
},
6172
config: {
6273
saved: 'Config Saved',

i18n/zh.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,23 @@ const zh = {
2727
votes: '投票',
2828
},
2929
reddit: {
30-
title: 'Reddit 榜单列表',
30+
title: 'Reddit 帖子',
3131
postName: '标题',
3232
content: '内容',
3333
comment: '评论',
3434
url: '链接',
3535
votes: '投票',
3636
topic: '话题',
3737
},
38+
v2ex: {
39+
title: 'V2EX 帖子',
40+
postName: '标题',
41+
comment: '评论',
42+
content: '详情',
43+
url: '链接',
44+
votes: 'Votes',
45+
topic: '节点',
46+
},
3847
spinner: {
3948
load: '数据拉取中...',
4049
fail: '程序错误, 你可以发送邮件至 <phillzou@gmail.com> 联系开发者',
@@ -57,6 +66,8 @@ const zh = {
5766
redditDesc: '获取 Reddit 信息列表',
5867
redditTopic: "获取相关话题列表,默认话题 'popular'",
5968
redditSort: '排序方式,可支持参数:top,best,new 和 hot,默认为 hot',
69+
v2ex: '获取 V2EX 信息列表',
70+
v2exNode: '节点名称: programmer、python、create、macos 等等,默认为 create',
6071
},
6172
config: {
6273
saved: '配置成功',

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"cheerio": "^1.0.0-rc.9",
3636
"commander": "^6.2.1",
3737
"execa": "^5.0.0",
38-
"he": "^1.2.0",
3938
"inquirer": "^8.1.0",
4039
"lodash": "^4.17.21",
4140
"ora": "^5.4.0"

utils/fetchReddit.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const axios = require('axios');
2-
const he = require('he');
32
const _ = require('lodash');
43
const ora = require('ora');
54
const t = require('./i18n');
@@ -40,7 +39,10 @@ async function fetchReddit(sort = 'hot', topic = 'popular') {
4039
console.log('----------------------------------------------');
4140
});
4241
spinner.stop();
43-
} catch (error) {}
42+
} catch (error) {
43+
console.log(error);
44+
spinner.fail(t('spinner.fail'));
45+
}
4446
}
4547

4648
module.exports = fetchReddit;

utils/fetchV2ex.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const axios = require('axios');
2+
const _ = require('lodash');
3+
const ora = require('ora');
4+
const t = require('./i18n');
5+
const { V2exBaseUrl } = require('../common/const');
6+
const chalk = require('chalk');
7+
8+
async function fetchV2ex(topic = 'create') {
9+
const url = `${V2exBaseUrl}/api/topics/show.json?node_name=${topic}`;
10+
const spinner = ora(t('spinner.load')).start();
11+
try {
12+
const { data } = await axios.get(url);
13+
spinner.stop();
14+
console.log(
15+
chalk.cyan(`-----------------------------------------
16+
🤖️ ${t('v2ex.title')}
17+
-----------------------------------------
18+
`),
19+
);
20+
data.forEach((item) => {
21+
const { title, url, content, node = {}, replies } = item;
22+
console.log(t('v2ex.postName'), ': ', chalk.cyan(title));
23+
console.log(
24+
`${t('v2ex.comment')}: `,
25+
chalk.yellow(replies),
26+
` | ${t('v2ex.topic')}: `,
27+
chalk.yellow(node.name),
28+
);
29+
console.log(t('v2ex.url'), ': ', chalk.dim(url));
30+
if (content !== '') {
31+
console.log(t('v2ex.content'), ': ', chalk.green(content));
32+
}
33+
console.log('----------------------------------------------');
34+
});
35+
spinner.stop();
36+
} catch (error) {
37+
console.log(error);
38+
spinner.fail(t('spinner.fail'));
39+
}
40+
}
41+
42+
module.exports = fetchV2ex;

utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const fetchHackerNews = require('./fetchHackerNews');
22
const fetchProductHunt = require('./fetchProductHunt');
33
const fetchGitHubTrending = require('./fetchGitHub');
44
const fetchReddit = require('./fetchReddit');
5+
const fetchV2ex = require('./fetchV2ex');
56
const config = require('./db');
67
const t = require('./i18n');
78

@@ -10,6 +11,7 @@ module.exports = {
1011
fetchProductHunt,
1112
fetchGitHubTrending,
1213
fetchReddit,
14+
fetchV2ex,
1315
config,
1416
t,
1517
};

0 commit comments

Comments
 (0)