auths
objectEnter the keyword or phrase (in quotes) to search for in Reddit posts and comments.
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
if(typeof params.search_keyword === 'undefined') {
$end('REQUIRED: Enter a keyword in steps.config')
}
this.search_keyword = params.search_keyword
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
$checkpoint = $checkpoint || {}
$checkpoint[params.q] = $checkpoint[params.q] || {postCheckpoint: 0, commentCheckpoint: 0}
this.postCheckpoint = $checkpoint[params.q].postCheckpoint
this.commentCheckpoint = $checkpoint[params.q].commentCheckpoint
Search term. Will search ALL possible fields
Number of results to return (Integer <= 500)
Sort results in a specific order ("asc" or "desc")
Return results after this date. Provide an epoch value or Integer + "s,m,h,d" (i.e. 30d for 30 days)
async
(params, auths) => {
}
const options = {
url: `https://api.pushshift.io/reddit/search/submission/`,
method: 'get',
params: {
ids: params.ids,
q: params.q,
'q:not': params['q:not'],
title: params.title,
'title:not': params['title:not'],
selftext: params.selftext,
'selftext:not': params['selftext:not'],
size: params.size,
fields: params.fields,
sort: params.sort,
sort_type: params.sort_type,
aggs: params.aggs,
author: params.author,
subreddit: params.subreddit,
after: params.after,
before: params.before,
score: params.score,
num_comments: params.num_comments,
over_18: params.over_18,
is_video: params.is_video,
locked: params.locked,
stickied: params.stickied,
spoiler: params.spoiler,
content_mode: params.content_mode,
frequency: params.frequency,
metadata: params.metadata
}
}
return (await require("@pipedreamhq/platform").axios(this, options)).data
Search term. Will search ALL possible fields
Number of results to return (Integer <= 500)
Sort results in a specific order ("asc" or "desc")
Return results after this date. Provide an epoch value or Integer + "s,m,h,d" (i.e. 30d for 30 days)
async
(params, auths) => {
}
const options = {
url: `https://api.pushshift.io/reddit/search/comment/`,
method: 'get',
params: {
q: params.q,
ids: params.ids,
size: params.size,
fields: params.fields,
sort: params.sort,
sort_type: params.sort_type,
aggs: params.aggs,
author: params.author,
subreddit: params.subreddit,
after: params.after,
before: params.before,
frequency: params.frequency,
metadata: params.metadata
}
}
return (await require("@pipedreamhq/platform").axios(this, options)).data
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
let maxTimestamp = steps.get_checkpoint.postCheckpoint
steps.search_reddit_posts.$return_value.forEach(function(element){
maxTimestamp = element.created_utc > maxTimestamp ? element.created_utc : maxTimestamp
})
this.newPostCheckpoint = $checkpoint[params.q].postCheckpoint = maxTimestamp
maxTimestamp = steps.get_checkpoint.commentCheckpoint
steps.search_reddit_comments.$return_value.forEach(function(element){
maxTimestamp = element.created_utc > maxTimestamp ? element.created_utc : maxTimestamp
})
this.newCommentTimestamp = $checkpoint[params.q].commentCheckpoint = maxTimestamp
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// consolidate the post and comment search results into a standard object with the keys: title, url and content
// we'll export this object so we can use it in later steps to generate message for email, slack, etc
const messages = []
const posts = steps.search_reddit_posts.$return_value
const comments = steps.search_reddit_comments.$return_value
let i
function generateMessage(type, obj) {
let message = {}
// identify the type of content and the author
message.title = `New ${type} by ${obj.author}`
message.timestamp = new Date(obj.created_utc * 1000)
message.url = `https://reddit.com${obj.permalink}`
if(type === 'post') {
// concatenate the title and post content if the message was a post
message.content = `${obj.title}: ${obj.selftext}`
} else if (type === 'comment') {
// save the body if the message was a comment
message.content = obj.body
}
return message
}
posts.forEach(function(element) {
messages.push(generateMessage('post', element))
})
comments.forEach(function(element) {
messages.push(generateMessage('comment', element))
})
if (messages.length > 0) {
this.summary = `${posts.length} new post${posts.length === 1 ? '' : 's' } and ${comments.length} comment${posts.length === 1 ? '' : 's' }`
} else {
$end(`No new posts or comments`)
}
return messages
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const results = steps.consolidate_results
let plainText = `Reddit Search Results (${steps.config.search_keyword.toUpperCase()}): ${results.summary.toUpperCase()}\n\n`
for (let i=0; i<results.$return_value.length; i++) {
let result = results.$return_value[i]
plainText += [result.title, result.timestamp, result.url, result.content, "\n======\n\n"].join("\n")
}
this.plainText = plainText
async
params => {
}
const options = {
subject: params.subject,
text: params.text,
}
if (params.html) {
options.html = params.html
}
if (params.include_collaborators) {
options.include_collaborators = params.include_collaborators
}
$send.email(options)
async
params => {
}
$end(params.reason)