default handling for osm picture
This commit is contained in:
parent
15bb11bf1e
commit
fc02ef60e3
BIN
assets/icecream.jpg
Normal file
BIN
assets/icecream.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 283 KiB |
BIN
assets/osm_default.jpg
Normal file
BIN
assets/osm_default.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 319 KiB |
BIN
assets/osm_tag.xcf
Normal file
BIN
assets/osm_tag.xcf
Normal file
Binary file not shown.
@ -1,17 +1,20 @@
|
||||
import Masto from "mastodon";
|
||||
import dotenv from "dotenv";
|
||||
import fs from "node-fs";
|
||||
|
||||
let local_node_env_conf = dotenv.config()
|
||||
|
||||
// console.log("conf", local_node_env_conf)
|
||||
|
||||
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)]
|
||||
}
|
||||
|
||||
|
||||
|
||||
let nowDate = new Date()
|
||||
|
||||
export let defaultConfigMasto = {
|
||||
@ -20,11 +23,17 @@ export let defaultConfigMasto = {
|
||||
language: 'fr',
|
||||
sensitive: false,
|
||||
reallySendPost: false,
|
||||
image: '',
|
||||
message: "Hey coucou! on est le" + nowDate,
|
||||
scheduled_at: ""
|
||||
}
|
||||
|
||||
|
||||
export function tokenForAuthorIsPresentInDotEnv(author) {
|
||||
console.log(" process.env['TOKEN_' + author.toUpperCase()]", process.env['TOKEN_' + author.toUpperCase()])
|
||||
return process.env['TOKEN_' + author.toUpperCase()];
|
||||
}
|
||||
|
||||
export function sendPostMastodon(config) {
|
||||
|
||||
// override defaults with input argument
|
||||
@ -32,12 +41,14 @@ export function sendPostMastodon(config) {
|
||||
...defaultConfigMasto,
|
||||
...config,
|
||||
}
|
||||
// require('dotenv').config();
|
||||
|
||||
|
||||
if (!config.reallySendPost) {
|
||||
console.log(" =========== le message ne sera PAS réellement posté sur le compte @" + config.author + "@"+ process.env.INSTANCE_MASTODON +" =========== ")}
|
||||
console.log(" =========== le message ne sera PAS réellement posté sur le compte @" + config.author + "@" + process.env.INSTANCE_MASTODON + " =========== ")
|
||||
} else {
|
||||
|
||||
console.log(" ")
|
||||
if (process.env['TOKEN_' + config.author.toUpperCase()]) {
|
||||
if (process.env.INSTANCE_MASTODON && tokenForAuthorIsPresentInDotEnv(config.author)) {
|
||||
|
||||
let visibility = 'public';
|
||||
let language = 'fr';
|
||||
@ -67,7 +78,7 @@ export function sendPostMastodon(config) {
|
||||
/**
|
||||
* envoi sans fichier joint
|
||||
*/
|
||||
if (!config.fichier) {
|
||||
if (!config.image) {
|
||||
|
||||
if (config.reallySendPost) {
|
||||
|
||||
@ -85,18 +96,45 @@ export function sendPostMastodon(config) {
|
||||
* 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 => {
|
||||
if (config.image) {
|
||||
|
||||
var id;
|
||||
console.log("envoi du média", config.image)
|
||||
if(config.image === 'osm_default.jpg'){
|
||||
id = '108787661095227871';
|
||||
params.media_ids = [id]
|
||||
masto.post('statuses', params).then(rep => {
|
||||
console.log("posté avec l'image osm_default déjà enregistrée")
|
||||
// console.log('rep', rep)
|
||||
// }, err => {
|
||||
// console.error(err)
|
||||
// })
|
||||
// res.render('index', {bodyReq: config})
|
||||
// }
|
||||
}, err => {
|
||||
|
||||
console.error(err)
|
||||
console.log("erreur T_T")
|
||||
})
|
||||
|
||||
}else{
|
||||
console.error('pas de token pour ' + config.author, process.env.TOKEN_curator)
|
||||
// upload new media
|
||||
return masto.post('media', {file: fs.createReadStream('assets/' + config.image)})
|
||||
.then(resp => {
|
||||
id = resp.data.id;
|
||||
params.media_ids = [id]
|
||||
masto.post('statuses', params).then(rep => {
|
||||
console.log('rep', rep)
|
||||
console.log("posté avec une nouvelle image, WOOT")
|
||||
}, err => {
|
||||
console.error(err)
|
||||
|
||||
console.log("erreur T_T")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
console.error(`pas de token pour l'auteur "${config.author}" ou pas d'instance mastodon définie`)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
// https://www.mediawiki.org/wiki/Manual:Random_page
|
||||
/**
|
||||
* Post de page aléatoire du wiki osm avec le compte curator
|
||||
*/
|
||||
import fetch from "node-fetch"
|
||||
import rp from "request-promise";
|
||||
import $ from "cheerio";
|
||||
@ -8,13 +11,16 @@ import {randomIntFromInterval, sendPostMastodon} from "./utils.js";
|
||||
|
||||
const __dirname = path.resolve();
|
||||
|
||||
// select one line of table to override description
|
||||
const selectionOverrideOfSectionTable = 2;
|
||||
const selectionOverrideOfLineTable = 7;
|
||||
|
||||
// select randomly a line
|
||||
// const selectionOverrideOfSectionTable = '';
|
||||
// const selectionOverrideOfLineTable = '';
|
||||
|
||||
const reallySendToot = false;
|
||||
// const reallySendToot = true;
|
||||
|
||||
function getRandomWikiOSMPage() {
|
||||
|
||||
@ -202,7 +208,7 @@ function checkExistenceOfWebPage(url) {
|
||||
|
||||
function makePostMessageFromObj(result) {
|
||||
return `
|
||||
# [Le tag OSM du jour : ${result.key}=${result.value}](${result.link})
|
||||
# 🗺️ [Le tag OSM du jour : ${result.key}=${result.value}](${result.link}) 🏷️
|
||||
${result.description.trim()}
|
||||
> ${result.long_desc.trim()}
|
||||
#osm #openstreetmap #wiki #rtfw
|
||||
@ -259,6 +265,7 @@ const res = getElementCartographique()
|
||||
function sendMessageWikiTagOfTheDay(message) {
|
||||
let configPost = {
|
||||
author: 'curator',
|
||||
image: 'osm_default.jpg',
|
||||
message,
|
||||
// reallySendPost: true,
|
||||
reallySendPost: reallySendToot,
|
||||
|
Loading…
Reference in New Issue
Block a user