Skip to content

Commit

Permalink
Merge pull request #2 from Phoenix181/livestream-add
Browse files Browse the repository at this point in the history
Added Livestream
  • Loading branch information
dfireBird authored Jan 9, 2020
2 parents 2c01756 + 758fc86 commit 9217cb9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ node index.js [options] [command]
scrappdit [options] [command]
```

Use `u` flag to get the top post titles of the user.
Use `u` or `user` command 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 post titles of the subreddit.
Use `s` or `subreddit` command to get the hot post titles of the subreddit.

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

Use `t` or `stream` command to get post titles from the subreddit and it constantly prints new post's titles as soons the someone posts it in subreddit.

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

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

```bash
Expand All @@ -54,6 +61,7 @@ List of commands avaiable:

- `user | u <username>` Get post titles from a user.
- `subreddit | s <subredditname>` Get post titles from a subreddit.
- `stream | t <subredditname>` Stream post titles from a subreddit.

## Contributing

Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Reddit = require('./src/Reddit');
const program = require('commander');
const livestream = require('./src/livestream');

program
.version('1.0.0')
Expand Down Expand Up @@ -36,6 +37,15 @@ program
}
});

program
.command('stream <subredditname>')
.alias('t')
.description('Streams the post titles from a specified subreddit')
.action((subredditname) => {
console.log('\x1b[34m', 'Ctrl-C to quit');
livestream(subredditname);
});

program.parse(process.argv);

if(program.count >= 99) {
Expand Down
50 changes: 49 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrapddit",
"version": "1.1.0",
"version": "1.2.0",
"description": "A app that retrieves posts from a subreddit or a reddit user.",
"main": "index.js",
"bin": "index.js",
Expand All @@ -24,6 +24,7 @@
},
"dependencies": {
"commander": "^4.0.1",
"snoostorm": "^1.3.0",
"snoowrap": "^1.20.1"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions src/livestream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const Reddit = require('./Reddit');
const {SubmissionStream} = require('snoostorm');

const livestream = (name) => {
const submissions = new SubmissionStream(Reddit, {subreddit: name, limit: 10, pollTime: 1000});
submissions.on('item', (submission) => {
console.log('\x1b[32m%s\x1b[0m', submission.title);
});
}

module.exports = livestream;

0 comments on commit 9217cb9

Please sign in to comment.