From c9bc576a15b1ba6207a5095b182b079fa84e3cf0 Mon Sep 17 00:00:00 2001 From: adb Date: Sun, 21 Feb 2021 15:07:14 +0100 Subject: [PATCH] only post media content --- node_app/main.js | 5 +++-- node_app/memeHandler.js | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/node_app/main.js b/node_app/main.js index 9055b59..9a3659c 100644 --- a/node_app/main.js +++ b/node_app/main.js @@ -15,7 +15,7 @@ tokenHandler.getAccessToken((accessToken) => { access_token: accessToken, }); let memeHandler = new MemeHandler(memeAPI, subreddits, allowedMedia); - executeAndSetInterval(() => { + executeAndSetInterval(function postRandomMeme(){ memeHandler.getRandomMeme(sub => { let status = `"${sub.title}"\n${sub.text}\nby ${sub.author}`; if (allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())){ @@ -24,7 +24,8 @@ tokenHandler.getAccessToken((accessToken) => { client.postMedia(status, filepath); }) }else{ - client.postStatus(status); + console.log("no valid media, fetching new sub") + postRandomMeme(); } }) }, interval); diff --git a/node_app/memeHandler.js b/node_app/memeHandler.js index 4e69bb8..dc2e078 100644 --- a/node_app/memeHandler.js +++ b/node_app/memeHandler.js @@ -11,6 +11,8 @@ export class MemeHandler{ getRandomMeme(callback){ this.request(this.memeAPI+this.randomFromArray(this.subreddits), (res) => { let sub = this.randomFromArray(res.subs); + console.log("got sub => "); + console.log(sub) callback(sub); }); } @@ -18,6 +20,7 @@ export class MemeHandler{ const request = https.get(url, (res) => { res.pipe(fs.createWriteStream(filepath)); res.on('end', () => { + console.log(`downloaded media => ${filepath}`); callback(); }) });