-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (40 loc) 路 1.28 KB
/
Copy pathapp.js
File metadata and controls
49 lines (40 loc) 路 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require('dotenv').config()
const Snoowrap = require('snoowrap');
const Snoostorm = require('snoostorm');
const util = require('util');
const moment = require('moment');
// App
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
// Make a .env with the following details
const r = new Snoowrap({
userAgent: 'reddit-bot-413DX',
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
username: process.env.REDDIT_USER,
password: process.env.REDDIT_PASS
});
const client = new Snoostorm(r);
const streamOpts = {
subreddit: 'all', // all
results: 25,
pollTime: 1500 // It updates every 1,1 seconds, this will allow some room to breathe for the API.
};
const submissionStream = client.SubmissionStream(streamOpts);
submissionStream.on("submission", function (post) {
var content = {
time: moment().calendar(),
username: post.author.name,
subreddit: post.subreddit.display_name,
link: post.url
};
io.emit('postdata', content);
});
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
const port = 80;
http.listen(process.env.PORT || port, function () {
console.log('The app is live on port 80 or your process.env.PORT');
});