async
(params, auths) => {
}
const config = {
url: `https://oauth.reddit.com/subreddits/mine/${params.where}`,
params: {
after: params.after,
before: params.before,
count: params.count,
include_categories: params.include_categories,
limit: params.limit,
show: params.show,
sr_detail: params.sr_detail,
},
headers: {
Authorization: `Bearer ${auths.reddit.oauth_access_token}`,
"User-Agent": "pipedream:v0.0.1 (by /r/pipedream)",
},
}
return await require("@pipedreamhq/platform").axios(this, config)
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const axios = require("axios");
// simplify things a bit
let mysubs = steps.get_subreddits_mine_where.$return_value.data.children.map(s => {
return s.data;
})
// title, displayName
let promises = [];
mysubs.forEach(sub => {
let url = 'https://engtbib844m2yqb.m.pipedream.net?subreddit='+sub.display_name;
promises.push(axios({method:'get', url}));
});
let result = await Promise.all(promises);
// global post array we can sort in a bit
this.posts = [];
for(let i=0;i<result.length;i++) {
this.posts = this.posts.concat(result[i].data.result);
}
this.posts.sort((a,b) => {
if(a.created_utc < b.created_utc) return 1;
if(a.created_utc >b.created_utc) return -1;
return 0;
});
console.log('total posts', this.posts.length);
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
let dotLeft = function(s, len) {
if(s.length < len) return s;
return s.substring(0, len)+'...';
};
this.subject = `Daily Reddit Report`;
this.body = `
<h2>Daily New Posts for Your Reddit Subscriptions</h2>
<p/>
`;
steps.get_and_sort.posts.forEach(p => {
// only show thumbnails when they aren't "self","default","nswf"
if(p.thumbnail === 'self' || p.thumbnail === 'default' || p.thumbnail === 'nsfw') delete p.thumbnail;
let text = '';
if(p.is_self) text = dotLeft(p.selftext,200);
this.body += `
<p>
${ p.thumbnail ? '<img src="'+p.thumbnail+'" align="left" style="margin-right:10px">':''}
<b>Subreddit: ${p.subreddit}</b><br/>
<b>Title: ${p.title}</b><br/>
URL: <a href="${p.url}">${p.url}</a><br/>
Reddit URL: <a href="https://www.reddit.com${p.permalink}">https://www.reddit.com${p.permalink}</a><br/>
Author: ${p.author}<br/>
<br clear="left">
${text}
</p>
`
});
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)