Daily Reddit Posts 2
@raymondcamden
code:
data:privatelast updated:4 years agoarchived
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,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
24
25
26
27
28
29
30
31
}
32
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);
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

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>  
  `
});
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)