Skip to content

Commit

Permalink
Merge pull request #1 from Phoenix181/add-count
Browse files Browse the repository at this point in the history
Add count
  • Loading branch information
dfireBird authored Dec 26, 2019
2 parents ef99e68 + eb7c7c6 commit 2c01756
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,34 @@ node index.js [options] [command]
scrappdit [options] [command]
```

Use `u` flag to get the top 25 posts titles of the user.
Use `u` flag to get the top post titles of the user.

```bash
node index.js u <username>
scrappdit u <username>
```

Use `s` flag to get the hot 25 posts titles of the subreddit.
Use `s` flag to get the hot post titles of the subreddit.

```bash
node index.js s <subredditname>
scrappdit s <subredditname>
```

Use `-c, --count <count>` option to get a specified number of post titles. The default count is 25.

```bash
node index.js u <username> -c <count>
node index.js s <subreddit name> -c <count>
```

List of options available:

- `-V, --version` output the version number
- `-V, --version` Output the version number

- `-h, --help` Output usage information

- `-h, --help` output usage information
- `-c, --count <count>` Specify the count of posts you want (default: 25);

List of commands avaiable:

Expand Down
32 changes: 21 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,42 @@ program
.version('1.0.0')
.description('Retrieves post titles from a subreddit or a reddit user. \n');

program
.option('-c, --count <count>', 'Specify the count of posts you want', '25');

program
.command('user <username>')
.alias('u')
.description('Get post titles from a user.')
.action((username) => {
Reddit.getUser(username).getSubmissions()
.then((Submissions) => {
const titles = Submissions.map((Submission) => {
return Submission.title;
});
console.log(titles);
})
.catch(console.log)
if(Number(program.count) < 99) {
Reddit.getUser(username)
.getSubmissions({ limit: Number(program.count) })
.map(post => post.title)
.then(console.log)
.catch(console.error);
}
});

program
.command('subreddit <subredditname>')
.alias('s')
.description('Get post titles from a subreddit.')
.action((subredditname) => {
Reddit.getSubreddit(subredditname).getHot().map(post => post.title)
.then(console.log)
.catch(console.error);
if(Number(program.count) < 99) {
Reddit.getSubreddit(subredditname)
.getHot({limit: Number(program.count)})
.map(post => post.title)
.then(console.log)
.catch(console.error);
}
});

program.parse(process.argv);

if(program.count >= 99) {
console.error('I can\'t display more than 99 items in console');
}

if(process.argv.length === 2)
console.error('No arguments provided. \nUsage: index [options] [command]');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrapddit",
"version": "1.0.0",
"version": "1.1.0",
"description": "A app that retrieves posts from a subreddit or a reddit user.",
"main": "index.js",
"bin": "index.js",
Expand Down

0 comments on commit 2c01756

Please sign in to comment.