hop
This commit is contained in:
parent
92e63f6550
commit
92596d56fd
@ -1,7 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="WEB_MODULE" version="4">
|
<module type="WEB_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.idea/dataSources" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/bin" />
|
||||||
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
28052
assets/documents/cipherbliss_tkwp_posts.json
Normal file
28052
assets/documents/cipherbliss_tkwp_posts.json
Normal file
File diff suppressed because one or more lines are too long
27577
assets/documents/tykayn_wptkblog_posts.json
Normal file
27577
assets/documents/tykayn_wptkblog_posts.json
Normal file
File diff suppressed because one or more lines are too long
12
helpers/describe_picture_folders.mjs
Normal file
12
helpers/describe_picture_folders.mjs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export default {
|
||||||
|
folders : [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
descriptions: ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
descriptions: ''
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
135
helpers/tkblogPost.js
Normal file
135
helpers/tkblogPost.js
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
// import fetch from "node-fetch"
|
||||||
|
// import rp from "request-promise";
|
||||||
|
// import $ from "cheerio";
|
||||||
|
import fs from "fs";
|
||||||
|
import Masto from "mastodon";
|
||||||
|
import path from 'path';
|
||||||
|
const __dirname = path.resolve();
|
||||||
|
const tkpostsjson = JSON.parse(fs.readFileSync(__dirname +"/assets/documents/tykayn_wptkblog_posts.json", 'utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let nowDate = new Date()
|
||||||
|
|
||||||
|
|
||||||
|
let defaultConfigMasto = {
|
||||||
|
author: 'curator',
|
||||||
|
visibility: 'public',
|
||||||
|
language: 'fr',
|
||||||
|
sensitive: false,
|
||||||
|
reallySendPost: false,
|
||||||
|
message: "Hey coucou! on est le" + nowDate,
|
||||||
|
scheduled_at: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendPostMastodon(config) {
|
||||||
|
|
||||||
|
// override defaults with input argument
|
||||||
|
config = {
|
||||||
|
...defaultConfigMasto,
|
||||||
|
...config,
|
||||||
|
}
|
||||||
|
// require('dotenv').config();
|
||||||
|
|
||||||
|
if (process.env['TOKEN_' + config.author.toUpperCase()]) {
|
||||||
|
|
||||||
|
let visibility = 'public';
|
||||||
|
let language = 'fr';
|
||||||
|
let sensitive = false;
|
||||||
|
|
||||||
|
let accessToken = process.env['TOKEN_' + config.author.toUpperCase()]
|
||||||
|
const masto = new Masto({
|
||||||
|
access_token: accessToken,
|
||||||
|
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
|
||||||
|
});
|
||||||
|
|
||||||
|
let params = {
|
||||||
|
status: config.message,
|
||||||
|
visibility,
|
||||||
|
language,
|
||||||
|
sensitive
|
||||||
|
}
|
||||||
|
if (config.cw) {
|
||||||
|
params['spoiler_text'] = config.cw
|
||||||
|
}
|
||||||
|
if (config.scheduled_at && config.scheduled_at_bool) {
|
||||||
|
let dateschedule = new Date(config.scheduled_at)
|
||||||
|
params['scheduled_at'] = dateschedule.toISOString()
|
||||||
|
}
|
||||||
|
console.log(config)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* envoi sans fichier joint
|
||||||
|
*/
|
||||||
|
if (!config.fichier) {
|
||||||
|
|
||||||
|
if (config.reallySendPost) {
|
||||||
|
|
||||||
|
masto.post('statuses', params).then(rep => {
|
||||||
|
// console.log('rep', rep)
|
||||||
|
console.log("posté, yay!")
|
||||||
|
}, err => {
|
||||||
|
console.error(err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* envoi avec fichier,
|
||||||
|
* on doit d'abord faire un upload du fichier,
|
||||||
|
* puis relier son id de media au nouveau post.
|
||||||
|
*/
|
||||||
|
// if (config.fichier) {
|
||||||
|
//
|
||||||
|
// masto.post('statuses', params).then(rep => {
|
||||||
|
// console.log('rep', rep)
|
||||||
|
// }, err => {
|
||||||
|
// console.error(err)
|
||||||
|
// })
|
||||||
|
// res.render('index', {bodyReq: config})
|
||||||
|
// }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.error('pas de token pour ' + config.author, process.env.TOKEN_curator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRandomElementOfArray(listItems) {
|
||||||
|
return listItems[Math.floor(Math.random() * listItems.length)]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getRandomLink() {
|
||||||
|
let filteredLinks = tkpostsjson.filter(elem => elem.post_status === 'publish')
|
||||||
|
return getRandomElementOfArray(filteredLinks)
|
||||||
|
}
|
||||||
|
|
||||||
|
function postLink() {
|
||||||
|
|
||||||
|
let postObject = getRandomLink()
|
||||||
|
console.log("envoi de post par le Curator")
|
||||||
|
|
||||||
|
let filteredExcerpt = postObject.post_content.replace(/<[^>]+>/g, '')
|
||||||
|
let counterLength = filteredExcerpt.length;
|
||||||
|
|
||||||
|
let limitExcerpt = 250
|
||||||
|
filteredExcerpt = filteredExcerpt.substring(0, limitExcerpt)
|
||||||
|
if(filteredExcerpt && counterLength > limitExcerpt){
|
||||||
|
filteredExcerpt = ' _'+filteredExcerpt+'..._'
|
||||||
|
}
|
||||||
|
|
||||||
|
let configPost = {
|
||||||
|
author: 'curator',
|
||||||
|
message: `# [${postObject.post_title}](${postObject.guid})
|
||||||
|
|
||||||
|
* ${postObject.post_date} - ${postObject.guid}
|
||||||
|
${filteredExcerpt}
|
||||||
|
* #tykayn #tkblog #blog`,
|
||||||
|
reallySendPost: true,
|
||||||
|
// reallySendPost: false,
|
||||||
|
}
|
||||||
|
sendPostMastodon(configPost)
|
||||||
|
}
|
||||||
|
|
||||||
|
postLink();
|
8
helpers/utils.js
Normal file
8
helpers/utils.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import Masto from "mastodon";
|
||||||
|
|
||||||
|
export function randomIntFromInterval(min, max) { // min and max included
|
||||||
|
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||||
|
}
|
||||||
|
export function getRandomElementOfArray(listItems) {
|
||||||
|
return listItems[Math.floor(Math.random() * listItems.length)]
|
||||||
|
}
|
@ -1,15 +1,14 @@
|
|||||||
// https://www.mediawiki.org/wiki/Manual:Random_page
|
// https://www.mediawiki.org/wiki/Manual:Random_page
|
||||||
import fetch from "node-fetch"
|
import fetch from "node-fetch"
|
||||||
|
|
||||||
import rp from "request-promise";
|
import rp from "request-promise";
|
||||||
|
|
||||||
import $ from "cheerio";
|
import $ from "cheerio";
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {getRandomElementOfArray, randomIntFromInterval} from "./utils.js";
|
||||||
|
|
||||||
const __dirname = path.resolve();
|
const __dirname = path.resolve();
|
||||||
|
|
||||||
|
|
||||||
function getRandomWikiOSMPage() {
|
function getRandomWikiOSMPage() {
|
||||||
|
|
||||||
// get all FR tags
|
// get all FR tags
|
||||||
@ -40,14 +39,6 @@ function getRandomWikiOSMPage() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function randomIntFromInterval(min, max) { // min and max included
|
|
||||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRandomElementOfArray(listItems) {
|
|
||||||
return listItems[Math.floor(Math.random() * listItems.length)]
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function getElementCartographique() {
|
export default function getElementCartographique() {
|
||||||
const url = "https://wiki.openstreetmap.org/wiki/FR:%C3%89l%C3%A9ments_cartographiques"
|
const url = "https://wiki.openstreetmap.org/wiki/FR:%C3%89l%C3%A9ments_cartographiques"
|
||||||
const titleLink = "#toc a"
|
const titleLink = "#toc a"
|
||||||
@ -96,15 +87,15 @@ export default function getElementCartographique() {
|
|||||||
value: '',
|
value: '',
|
||||||
description: ''
|
description: ''
|
||||||
}
|
}
|
||||||
cells.each((i,element)=>{
|
cells.each((i, element) => {
|
||||||
console.log("cell element", i, $(element).text().trim())
|
console.log("cell element", i, $(element).text().trim())
|
||||||
if(i===0){
|
if (i === 0) {
|
||||||
result.key = $(element).text().trim();
|
result.key = $(element).text().trim();
|
||||||
}
|
}
|
||||||
if(i===1){
|
if (i === 1) {
|
||||||
result.value = $(element).text().trim();
|
result.value = $(element).text().trim();
|
||||||
}
|
}
|
||||||
if(i===3){
|
if (i === 3) {
|
||||||
result.description = $(element).text().trim();
|
result.description = $(element).text().trim();
|
||||||
}
|
}
|
||||||
// let cell = $(element).find("td");
|
// let cell = $(element).find("td");
|
||||||
@ -126,6 +117,10 @@ export default function getElementCartographique() {
|
|||||||
|
|
||||||
result.link = `https://wiki.openstreetmap.org/wiki/FR:Tag:${result.key}=${result.value}`
|
result.link = `https://wiki.openstreetmap.org/wiki/FR:Tag:${result.key}=${result.value}`
|
||||||
console.log("result", result)
|
console.log("result", result)
|
||||||
|
|
||||||
|
// aller chercher le lien
|
||||||
|
// image de description:
|
||||||
|
let imgSelector = ".description a.image img"
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
6056
package-lock.json
generated
Normal file
6056
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@
|
|||||||
"name": "mastodon-multi-account",
|
"name": "mastodon-multi-account",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./bin/www",
|
"start": "node ./bin/www",
|
||||||
"publish": "node ./publisher.js",
|
"publish": "node ./publisher.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user