start curator recommendations
This commit is contained in:
parent
7fa3b34b08
commit
ac38059f80
@ -2,6 +2,5 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/mastodon_multi_account" vcs="Git" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
131
helpers/curator_recommendation.mjs
Normal file
131
helpers/curator_recommendation.mjs
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
|
||||||
|
// import sendPostMastodon from "./libs/utils.mjs";
|
||||||
|
import axios from "axios"
|
||||||
|
import sharp from "sharp"
|
||||||
|
import path from "path"
|
||||||
|
import fs from "fs"
|
||||||
|
import os from "os"
|
||||||
|
import https from "https"
|
||||||
|
|
||||||
|
|
||||||
|
const downloadImage = async (url, name) => {
|
||||||
|
const outputPath = path.join(__dirname, 'images', name);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const stats = await fs.promises.stat(outputPath);
|
||||||
|
|
||||||
|
if (stats.isFile()) {
|
||||||
|
console.log(`${name} already downloaded`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code == 'ENOENT') {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await axios.get(url, { responseType: 'arraybuffer' });
|
||||||
|
const buffer = Buffer.from(response.data, 'binary');
|
||||||
|
|
||||||
|
await fs.promises.writeFile(outputPath, buffer);
|
||||||
|
|
||||||
|
console.log(`Downloaded ${name} and saved to ${outputPath}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function makePicture(){
|
||||||
|
|
||||||
|
|
||||||
|
// URL des images à combiner
|
||||||
|
const urls = [
|
||||||
|
'https://mastodon.cipherbliss.com/system/cache/accounts/avatars/111/167/114/936/998/027/original/a80c6e973a5ebfa4.jpg',
|
||||||
|
'https://mastodon.cipherbliss.com/system/cache/accounts/avatars/111/322/992/248/243/542/original/23520c84291a6c41.png',
|
||||||
|
'https://mastodon.cipherbliss.com/system/cache/accounts/avatars/111/472/478/271/279/314/original/938c74ffb49473d1.jpg'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Noms des images à combiner
|
||||||
|
const names = ['Image 1', 'Image 2', 'Image 3'];
|
||||||
|
|
||||||
|
// Largeur totale de l'image combinée
|
||||||
|
const totalWidth = 800;
|
||||||
|
|
||||||
|
// Hauteur totale de l'image combinée
|
||||||
|
const totalHeight = 600;
|
||||||
|
// Créer un dossier temporaire pour stocker les images téléchargées
|
||||||
|
const TEMP_DIR_NAME ='my-temp-dir';
|
||||||
|
|
||||||
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), TEMP_DIR_NAME));
|
||||||
|
|
||||||
|
console.log('tempDir:',tempDir)
|
||||||
|
|
||||||
|
Promise.all(urls.map((url, index) => {
|
||||||
|
// Télécharger l'image
|
||||||
|
return downloadImage(url)
|
||||||
|
}))
|
||||||
|
.then((filePaths) => {
|
||||||
|
// Combiner les images en une seule image
|
||||||
|
return sharp(filePaths[0])
|
||||||
|
.resize(totalWidth / 3, totalHeight)
|
||||||
|
.append([
|
||||||
|
sharp(filePaths[1]).resize(totalWidth / 3, totalHeight),
|
||||||
|
sharp(filePaths[2]).resize(totalWidth / 3, totalHeight)
|
||||||
|
])
|
||||||
|
.toBuffer();
|
||||||
|
})
|
||||||
|
.then((buffer) => {
|
||||||
|
// Enregistrer l'image combinée
|
||||||
|
const outputFilePath = path.join(tempDir, 'combined.jpg');
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.writeFile(outputFilePath, buffer, (error) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve(outputFilePath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then((outputFilePath) => {
|
||||||
|
// Afficher l'image combinée
|
||||||
|
console.log(`Combined image saved to ${outputFilePath}`);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function getFollowers(username, instance) {
|
||||||
|
const url = `https://${instance}/api/v1/accounts/${username}/following`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(url);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const username = '1';
|
||||||
|
const instance ='mastodon.cipherbliss.com';
|
||||||
|
|
||||||
|
const followers = await getFollowers(username, instance);
|
||||||
|
|
||||||
|
console.log('followers', followers.length)
|
||||||
|
|
||||||
|
const randomFollowers = followers.sort(() => Math.random() - 0.5)
|
||||||
|
|
||||||
|
const selection = randomFollowers.slice(0, 3)
|
||||||
|
console.log('Random followers:', randomFollowers.length);
|
||||||
|
|
||||||
|
selection.forEach(elem=>{
|
||||||
|
console.log('selection', elem.username , elem.avatar_static)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// main();
|
||||||
|
makePicture();
|
@ -26,12 +26,14 @@
|
|||||||
"webpage": "^0.3.0"
|
"webpage": "^0.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"axios": "^1.6.2",
|
||||||
"cheerio": "^1.0.0-rc.12",
|
"cheerio": "^1.0.0-rc.12",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"https": "^1.0.0",
|
"https": "^1.0.0",
|
||||||
"node-fetch": "^3.2.10",
|
"node-fetch": "^3.2.10",
|
||||||
"nodemon": "^2.0.22",
|
"nodemon": "^2.0.22",
|
||||||
|
"path": "^0.12.7",
|
||||||
"request-promise": "^4.2.6",
|
"request-promise": "^4.2.6",
|
||||||
"sharp": "^0.31.2"
|
"sharp": "^0.32.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user