From 36dd87ca0dc49570d83614e6f84cb520523db6ba Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 5 Jul 2023 14:17:30 +0200 Subject: [PATCH] plan recommend bot --- .../screenshot_missing_translations.sh | 0 assets/bash_scripts/screenshot_org_roam_ui.sh | 3 ++ .../wip/curation_following_recommendation.mjs | 14 ++--- routes/index.js | 54 +++++++++---------- 4 files changed, 36 insertions(+), 35 deletions(-) rename {helpers/wip => assets/bash_scripts}/screenshot_missing_translations.sh (100%) create mode 100644 assets/bash_scripts/screenshot_org_roam_ui.sh diff --git a/helpers/wip/screenshot_missing_translations.sh b/assets/bash_scripts/screenshot_missing_translations.sh similarity index 100% rename from helpers/wip/screenshot_missing_translations.sh rename to assets/bash_scripts/screenshot_missing_translations.sh diff --git a/assets/bash_scripts/screenshot_org_roam_ui.sh b/assets/bash_scripts/screenshot_org_roam_ui.sh new file mode 100644 index 0000000..8c15817 --- /dev/null +++ b/assets/bash_scripts/screenshot_org_roam_ui.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# org roam ui +squint screenshot --selector '.force-graph-container' http://localhost:35901/ --out-file "./documents/screenshots/org_roam_ui.jpg" --single-page diff --git a/helpers/wip/curation_following_recommendation.mjs b/helpers/wip/curation_following_recommendation.mjs index a8a7dc0..ed1738e 100644 --- a/helpers/wip/curation_following_recommendation.mjs +++ b/helpers/wip/curation_following_recommendation.mjs @@ -7,12 +7,6 @@ const __dirname = path.resolve(); // choisir un type de publication au hasard dans les dossiers "picture" -console.log(typeOfFolder) - -const folderMemeUnpublished = 'assets/pictures/meme/not_published/' -const folderMemePublished = 'assets/pictures/meme/published/' -const list_unpublished_images = listFilesOfFolder(folderMemeUnpublished) - const reallySendPost = false; // const reallySendPost = true; @@ -20,8 +14,16 @@ let allFollows = { } +function convertFollowersToArray(){ + +} function selectXRandomElementsFromFollowers(count){ + let elementsSelected = [] + let followersList = convertFollowersToArray(allFollows) + for (let ii=0; ii < count; ii++){ + elementsSelected.push(getRandomElementOfArray(followersList)) + } return [] } diff --git a/routes/index.js b/routes/index.js index f379a43..048be9f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,10 +1,10 @@ + + var express = require('express') var router = express.Router() var sqlite3 = require('sqlite3') var Masto = require('mastodon') -// import accounts_to_select from '../src/configs.mjs' - const accounts_to_select = [ { label: 'tykayn', @@ -236,13 +236,6 @@ router.get('/publish-last-entry', function (req, res, next) { let enable_post = false -// Get the user to open up the url in their browser and get the code -// oauth.getOAuthAccessToken('code from the authorization page that user should paste into your app', -// {grant_type: 'authorization_code', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob'}, -// function (err, accessToken, refreshToken, res) { -// -// console.log(err, accessToken, refreshToken , res); - const masto = new Masto({ access_token: accessToken, api_url: env.parsed.INSTANCE_MASTODON + '/api/v1/', @@ -305,6 +298,8 @@ router.get('/dispatch-publication-in-time', function (req, res, next) { }) + + router.post('/direct-post', function (req, res, next) { let env = require('dotenv').config({ path: __dirname + '/../.env' }) @@ -316,7 +311,10 @@ router.post('/direct-post', function (req, res, next) { let author = req.body.author.toUpperCase() console.log('vérif token pour', author) let access_token = env.parsed['TOKEN_' + author] - + const masto = new Masto({ + access_token: access_token, + api_url: env.parsed.INSTANCE_MASTODON + '/api/v1/', + }) console.log('token', access_token) if (access_token) { @@ -325,10 +323,7 @@ router.post('/direct-post', function (req, res, next) { let sensitive = false console.log('accessToken', access_token) - const masto = new Masto({ - access_token: access_token, - api_url: env.parsed.INSTANCE_MASTODON + '/api/v1/', - }) + let params = { status: req.body.message, @@ -349,29 +344,30 @@ router.post('/direct-post', function (req, res, next) { if (!req.body.fichier) { - masto.post('statuses', params).then(rep => { - console.log('rep', rep) - console.log('\n message bien envoyé') - }, err => { - console.error(err) - }) + console.log(' pas de fichier dans le post') + sendPostMastodon(params, masto) res.render('index', { bodyReq: req.body }) } // TODO prise en charge des fichiers joints - // if (req.body.fichier) { - // - // masto.post('statuses', params).then(rep => { - // console.log('rep', rep) - // }, err => { - // console.error(err) - // }) - // res.render('index', {bodyReq: req.body}) - // } + if (req.body.fichier) { + console.log(' envoi avec fichier') + sendPostMastodon(params, masto) + res.render('index', {bodyReq: req.body}) + } } else { console.error('pas de token pour ' + req.body.author) } }) +function sendPostMastodon(config, masto){ + masto.post('statuses', config).then(rep => { + console.log('rep', rep) + console.log('\n message bien envoyé') + }, err => { + console.error(err) + }) +} + module.exports = router