Last active
April 10, 2018 13:43
-
-
Save anthonytxie/b2b55d66b6f12993c9da82c238a382f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetchComments = async (startDate, limit) => { | |
console.log(`beginning comment fetch from ${startDate} to ${endDate}`); | |
while (startDate < endDate) { | |
// gets the first limit comments after startDate | |
const response = await axios.get( | |
`https://apiv2.pushshift.io/reddit/search/comment/?q=hodl&size=${limit}&after=${startDate | |
.toString() | |
.substr(0, 10)}` | |
); | |
const comments = response.data.data; | |
// prep comments for db | |
const commentDocuments = comments.map(comment => { | |
return { | |
commentDate: moment.unix(comment.created_utc).format("MM/DD/YYYY"), | |
subreddit: comment.subreddit, | |
body: comment.body | |
}; | |
}); | |
console.log( | |
`insert (${new Date(_.first(comments).created_utc * 1000)} -> ${new Date( | |
_.last(comments).created_utc * 1000 | |
)})` | |
); | |
await Comment.insertMany(commentDocuments).catch(e => console.log(e)); | |
startDate = _.last(comments).created_utc * 1000; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment