Daily Reddit Posts 3
@raymondcamden
code:
data:privatelast updated:1 year ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
Cron Scheduler
Deploy to configure a custom schedule
This workflow runs on Pipedream's servers and is triggered on a custom schedule.
steps.
get_subreddits_mine_where
Get subreddits the user has a relationship with. The where parameter chooses which subreddits are returned as follows: subscriber - subreddits the user is subscribed to contributor - subreddits the user is an approved user in moderator - subreddits the user is a moderator of streams - subscribed to subreddits that contain hosted video links See also: /api/subscribe, /api/friend, and /api/accept_moderator_invite. This endpoint is a listing.
auth
(auths.reddit)
params
Where
 
string ·params.where
Optional
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
}
19
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)
steps.
get_and_sort
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
}
23
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.slice(0,10));
}
steps.
format_email
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
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

let dotLeft = function(s, len) {
  if(s.length < len) return s;
  return s.substring(0, len)+'...';
};

let lastSub = '';

this.subject = `Daily Reddit Report`;
this.body = `
<h1>Daily New Posts for Your Reddit Subscriptions</h1>
<p/>
`;
steps.get_and_sort.posts.forEach(p => {
  // only show thumbnails when they aren't "self","default","nswf" - or more broadly, not a url
  if(p.thumbnail.indexOf('http') === -1) delete p.thumbnail;
  let text = '';
  if(p.is_self) text = dotLeft(p.selftext,200);
  if(p.subreddit !== lastSub) {
    this.body += `<hr/><h2>${p.subreddit}</h2>`;
    lastSub = p.subreddit;
  }
  this.body += `
<p>
${ p.thumbnail ? '<img src="'+p.thumbnail+'" align="left" style="margin-right:10px">':''}
<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>  
  `
});
steps.
email_me
Customize and send an email to the email address you registered with Pipedream. The email will be sent by notifications@pipedream.com.
params
Subject
 
string ·params.subject
Text
 
string ·params.text
Optional
code
async params => {
1
2
3
4
5
6
7
8
9
10
11
12
}
13
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)