forked from abdulhannanali/redditlist-scrape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetoverlaydata.js
37 lines (30 loc) · 902 Bytes
/
getoverlaydata.js
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
const mkdirp = require("mkdirp")
const request = require("request")
const fs = require("fs")
const async = require("async")
let overlayurl = "http://redditlist.com/getoverlaydata"
mkdirp.sync("./subredditdata/")
var subreddits = JSON.parse(fs.readFileSync("./subredditlist.json", "utf-8"))
async.parallelLimit(subreddits.map(function (subreddit) {
return function (callback) {
request({
method: "POST",
uri: overlayurl,
form: {
subreddit: subreddit.targetSubreddit,
adultfilter: subreddit.targetFilter
}
}, function (error, response, body) {
try {
if (body && JSON.parse(body)) {
console.log("Subreddit " + subreddit.targetSubreddit)
fs.writeFile("./subredditdata/" + subreddit.targetSubreddit + ".json", body)
}
}
catch (error) {}
callback(undefined, response)
})
}
}), 20, function (error, results) {
console.log(results.length)
})