add rss feed ability

This commit is contained in:
Tykayn 2023-03-03 15:19:09 +01:00 committed by tykayn
parent 716905487e
commit 81f4f0fd1a
9 changed files with 4153 additions and 2913 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

View File

@ -1,9 +1,10 @@
#!/bin/bash
nvm use 16
cd /home/tykayn/www/multi-account-post-schedule-mastodon
cd assets/documents
#cd assets/documents
# get rss feed of afis fr website in documents
echo "get afis science RSS feed" | tee -a /home/tykayn/log_autopost.txt
wget --no-check-certificate --no-directories -O ./../documents/afis_rss.xml https://afis.org/rss.xml
#echo "get afis science RSS feed" | tee -a /home/tykayn/log_autopost.txt
#wget --no-check-certificate --no-directories -O ./../documents/afis_rss.xml https://afis.org/rss.xml
#cd ../..
node helpers/afis_science.mjs --force | tee -a /home/tykayn/log_autopost.txt 2>&1

View File

@ -1,6 +1,8 @@
#!/bin/bash
wget --no-check-certificate --no-directories -O ./../documents/afis_rss.xml https://afis.org/rss.xml
wget --no-check-certificate --no-directories -O ./../assets/blog_posts_medias/afis_picture_of_the_day.jpg https://www.afis.org/local/cache-gd2/51/ab5523b710ad2cafd3b841d9e1df53.jpg?1675290946
wget --no-check-certificate --no-directories -O ./../documents/ourworldindata.html https://ourworldindata.org/blog
wget --no-check-certificate --no-directories -O ./../documents/elements_cartographiques.html https://wiki.openstreetmap.org/wiki/FR:%C3%89l%C3%A9ments_cartographiques
wget --no-check-certificate --no-directories -O ./../documents/wiki_osm_traductions_incompletes.html https://wiki.openstreetmap.org/wiki/Category:FR:Traduction_incompl%C3%A8te

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8"/>
<title>FR:Éléments cartographiques - OpenStreetMap Wiki</title>
<script>document.documentElement.className="client-js";RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":[",\t."," \t,"],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],"wgRequestId":"ca15cd7a222e5325ae72a013","wgCSPNonce":false,"wgCanonicalNamespace":"FR","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":202,"wgPageName":"FR:Éléments_cartographiques","wgTitle":"Éléments cartographiques","wgCurRevisionId":1764163,"wgRevisionId":1764163,"wgArticleId":4478,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Pages with script errors","Pages where template include size is exceeded","Pages unavailable in French","Pages with maps","FR:Éléments cartographiques","FR:Sémantique"],"wgPageContentLanguage":"fr","wgPageContentModel":"wikitext","wgRelevantPageName":
<script>document.documentElement.className="client-js";RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":[",\t."," \t,"],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],"wgRequestId":"c01c9a581cd07360dec802c6","wgCSPNonce":false,"wgCanonicalNamespace":"FR","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":202,"wgPageName":"FR:Éléments_cartographiques","wgTitle":"Éléments cartographiques","wgCurRevisionId":1764163,"wgRevisionId":1764163,"wgArticleId":4478,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Pages with script errors","Pages where template include size is exceeded","Pages unavailable in French","Pages with maps","FR:Éléments cartographiques","FR:Sémantique"],"wgPageContentLanguage":"fr","wgPageContentModel":"wikitext","wgRelevantPageName":
"FR:Éléments_cartographiques","wgRelevantArticleId":4478,"wgIsProbablyEditable":false,"wgRelevantPageIsProbablyEditable":false,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgMFDisplayWikibaseDescriptions":{"search":false,"nearby":false,"watchlist":false,"tagline":false},"wgVisualEditor":{"pageLanguageCode":"fr","pageLanguageDir":"ltr","pageVariantFallbacks":"fr"},"wgULSAcceptLanguageList":[],"wgULSCurrentAutonym":"English","wgVector2022PreviewPages":[],"ScribuntoErrors":["\u003Cp\u003EToo many Data Items entities accessed.\u003C/p\u003E\u003Cp\u003ENo further details are available.\u003C/p\u003E","\u003Cp\u003EToo many Data Items entities accessed.\u003C/p\u003E\u003Cp\u003ENo further details are available.\u003C/p\u003E","\u003Cp\u003EToo many Data Items entities accessed.\u003C/p\u003E\u003Cp\u003ENo further details are available.\u003C/p\u003E","\u003Cp\u003EToo many Data Items entities accessed.\u003C/p\u003E\u003Cp\u003ENo further details are available.\u003C/p\u003E",
"\u003Cp\u003EToo many Data Items entities accessed.\u003C/p\u003E\u003Cp\u003ENo further details are available.\u003C/p\u003E"],"wgEditSubmitButtonLabelPublish":false,"wgULSPosition":"personal","wgULSisCompactLinksEnabled":true};RLSTATE={"site.styles":"ready","user.styles":"ready","user":"ready","user.options":"loading","ext.kartographer.style":"ready","skins.vector.styles.legacy":"ready","ext.OsmWikibase-all":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.pt":"ready"};RLPAGEMODULES=["ext.kartographer.frame","ext.scribunto.errors","site","mediawiki.page.ready","mediawiki.toc","skins.vector.legacy.js","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.gadget.taginfo","ext.gadget.dataitemlinks","ext.uls.compactlinks","ext.uls.interface"];</script>
<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.implement("user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"});});});</script>
@ -14049,12 +14049,12 @@ On en trouve le long des routes et des chemins dans divers pays d'Europe: Allema
</p>
<!--
NewPP limit report
Cached time: 20230303111013
Cached time: 20230303123740
Cache expiry: 86400
Reduced expiry: false
Complications: [showtoc]
CPU time usage: 23.353 seconds
Real time usage: 38.508 seconds
CPU time usage: 23.103 seconds
Real time usage: 38.289 seconds
Preprocessor visited node count: 251259/1000000
Postexpand include size: 2097152/2097152 bytes
Template argument size: 503399/2097152 bytes
@ -14062,26 +14062,26 @@ Highest expansion depth: 29/100
Expensive parser function count: 259/500
Unstrip recursion depth: 0/20
Unstrip postexpand size: 3331/5000000 bytes
Lua time usage: 11.490/15 seconds
Lua virtual size: 9711616/52428800 bytes
Lua time usage: 10.670/15 seconds
Lua virtual size: 9846784/52428800 bytes
Lua estimated memory usage: 0 bytes
Number of Wikibase entities loaded: 75/250
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00% 33362.676 1 -total
43.42% 14487.628 1072 Template:Valuelink
32.77% 10934.345 1327 Template:Keylink
11.41% 3807.038 1 Template:FR:Map_Features:shop
11.40% 3803.256 1 Template:Map_Features:shop
9.28% 3097.383 1 Template:FR:Map_Features:amenity
9.26% 3090.730 1 Template:Map_Features:amenity
8.99% 3000.149 107 Template:LangSwitch
8.65% 2885.185 99 Template:Icon
7.42% 2476.523 1 Template:FR:Map_Features:highway
100.00% 33459.274 1 -total
43.65% 14605.340 1072 Template:Valuelink
32.67% 10930.326 1327 Template:Keylink
11.47% 3837.618 1 Template:FR:Map_Features:shop
11.46% 3833.006 1 Template:Map_Features:shop
9.20% 3077.024 1 Template:FR:Map_Features:amenity
9.18% 3070.675 1 Template:Map_Features:amenity
9.03% 3021.786 107 Template:LangSwitch
8.72% 2916.499 99 Template:Icon
7.85% 2627.527 1 Template:FR:Map_Features:highway
-->
<!-- Saved in parser cache with key wiki:pcache:idhash:4478-0!canonical and timestamp 20230303110934 and revision id 1764163.
<!-- Saved in parser cache with key wiki:pcache:idhash:4478-0!canonical and timestamp 20230303123701 and revision id 1764163.
-->
</div>
<div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://wiki.openstreetmap.org/w/index.php?title=FR:Éléments_cartographiques&amp;oldid=1764163">https://wiki.openstreetmap.org/w/index.php?title=FR:Éléments_cartographiques&amp;oldid=1764163</a>"</div></div>
@ -14288,6 +14288,6 @@ Transclusion expansion time report (%,ms,calls,template)
</footer>
<script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"23.353","walltime":"38.508","ppvisitednodes":{"value":251259,"limit":1000000},"postexpandincludesize":{"value":2097152,"limit":2097152},"templateargumentsize":{"value":503399,"limit":2097152},"expansiondepth":{"value":29,"limit":100},"expensivefunctioncount":{"value":259,"limit":500},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":3331,"limit":5000000},"entityaccesscount":{"value":75,"limit":250},"timingprofile":["100.00% 33362.676 1 -total"," 43.42% 14487.628 1072 Template:Valuelink"," 32.77% 10934.345 1327 Template:Keylink"," 11.41% 3807.038 1 Template:FR:Map_Features:shop"," 11.40% 3803.256 1 Template:Map_Features:shop"," 9.28% 3097.383 1 Template:FR:Map_Features:amenity"," 9.26% 3090.730 1 Template:Map_Features:amenity"," 8.99% 3000.149 107 Template:LangSwitch"," 8.65% 2885.185 99 Template:Icon"," 7.42% 2476.523 1 Template:FR:Map_Features:highway"]},"scribunto":{"limitreport-timeusage":{"value":"11.490","limit":"15"},"limitreport-virtmemusage":{"value":9711616,"limit":52428800},"limitreport-estmemusage":0},"cachereport":{"timestamp":"20230303111013","ttl":86400,"transientcontent":false}}});mw.config.set({"wgBackendResponseTime":38873});});</script>
<script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"23.103","walltime":"38.289","ppvisitednodes":{"value":251259,"limit":1000000},"postexpandincludesize":{"value":2097152,"limit":2097152},"templateargumentsize":{"value":503399,"limit":2097152},"expansiondepth":{"value":29,"limit":100},"expensivefunctioncount":{"value":259,"limit":500},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":3331,"limit":5000000},"entityaccesscount":{"value":75,"limit":250},"timingprofile":["100.00% 33459.274 1 -total"," 43.65% 14605.340 1072 Template:Valuelink"," 32.67% 10930.326 1327 Template:Keylink"," 11.47% 3837.618 1 Template:FR:Map_Features:shop"," 11.46% 3833.006 1 Template:Map_Features:shop"," 9.20% 3077.024 1 Template:FR:Map_Features:amenity"," 9.18% 3070.675 1 Template:Map_Features:amenity"," 9.03% 3021.786 107 Template:LangSwitch"," 8.72% 2916.499 99 Template:Icon"," 7.85% 2627.527 1 Template:FR:Map_Features:highway"]},"scribunto":{"limitreport-timeusage":{"value":"10.670","limit":"15"},"limitreport-virtmemusage":{"value":9846784,"limit":52428800},"limitreport-estmemusage":0},"cachereport":{"timestamp":"20230303123740","ttl":86400,"transientcontent":false}}});mw.config.set({"wgBackendResponseTime":263});});</script>
</body>
</html>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8"/>
<title>Category:FR:Traduction incomplète - OpenStreetMap Wiki</title>
<script>document.documentElement.className="client-js";RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"112b28409c26e53c5b5b43c3","wgCSPNonce":false,"wgCanonicalNamespace":"Category","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":14,"wgPageName":"Category:FR:Traduction_incomplète","wgTitle":"FR:Traduction incomplète","wgCurRevisionId":1434898,"wgRevisionId":1434898,"wgArticleId":145786,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Translation not complete/translations","FR:Traduction du wiki"],"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Category:FR:Traduction_incomplète","wgRelevantArticleId":145786,"wgIsProbablyEditable":false,
<script>document.documentElement.className="client-js";RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"b0d07ecf0525936f776f49fd","wgCSPNonce":false,"wgCanonicalNamespace":"Category","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":14,"wgPageName":"Category:FR:Traduction_incomplète","wgTitle":"FR:Traduction incomplète","wgCurRevisionId":1434898,"wgRevisionId":1434898,"wgArticleId":145786,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Translation not complete/translations","FR:Traduction du wiki"],"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Category:FR:Traduction_incomplète","wgRelevantArticleId":145786,"wgIsProbablyEditable":false,
"wgRelevantPageIsProbablyEditable":false,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgMFDisplayWikibaseDescriptions":{"search":false,"nearby":false,"watchlist":false,"tagline":false},"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgULSAcceptLanguageList":[],"wgULSCurrentAutonym":"English","wgVector2022PreviewPages":[],"wgEditSubmitButtonLabelPublish":false,"wgULSPosition":"personal","wgULSisCompactLinksEnabled":true};RLSTATE={"site.styles":"ready","user.styles":"ready","user":"ready","user.options":"loading","mediawiki.action.styles":"ready","mediawiki.helplink":"ready","skins.vector.styles.legacy":"ready","ext.OsmWikibase-all":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.tmh.player.styles":"ready","ext.uls.pt":"ready"};RLPAGEMODULES=["site","mediawiki.page.ready","skins.vector.legacy.js","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.gadget.taginfo",
"ext.gadget.dataitemlinks","ext.tmh.player","ext.uls.compactlinks","ext.uls.interface"];</script>
<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.implement("user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"});});});</script>
@ -414,6 +414,6 @@ Transclusion expansion time report (%,ms,calls,template)
</footer>
<script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"0.084","walltime":"0.132","ppvisitednodes":{"value":517,"limit":1000000},"postexpandincludesize":{"value":23048,"limit":2097152},"templateargumentsize":{"value":926,"limit":2097152},"expansiondepth":{"value":10,"limit":100},"expensivefunctioncount":{"value":13,"limit":500},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":0,"limit":5000000},"entityaccesscount":{"value":0,"limit":250},"timingprofile":["100.00% 90.550 1 -total"," 81.48% 73.778 1 Template:Languages"," 18.21% 16.487 2 Template:Tl"," 1.77% 1.606 1 Template:Purge"]},"scribunto":{"limitreport-timeusage":{"value":"0.040","limit":"15"},"limitreport-virtmemusage":{"value":6246400,"limit":52428800},"limitreport-estmemusage":0},"cachereport":{"timestamp":"20230303065314","ttl":86400,"transientcontent":false}}});mw.config.set({"wgBackendResponseTime":169});});</script>
<script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"0.084","walltime":"0.132","ppvisitednodes":{"value":517,"limit":1000000},"postexpandincludesize":{"value":23048,"limit":2097152},"templateargumentsize":{"value":926,"limit":2097152},"expansiondepth":{"value":10,"limit":100},"expensivefunctioncount":{"value":13,"limit":500},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":0,"limit":5000000},"entityaccesscount":{"value":0,"limit":250},"timingprofile":["100.00% 90.550 1 -total"," 81.48% 73.778 1 Template:Languages"," 18.21% 16.487 2 Template:Tl"," 1.77% 1.606 1 Template:Purge"]},"scribunto":{"limitreport-timeusage":{"value":"0.040","limit":"15"},"limitreport-virtmemusage":{"value":6246400,"limit":52428800},"limitreport-estmemusage":0},"cachereport":{"timestamp":"20230303065314","ttl":86400,"transientcontent":false}}});mw.config.set({"wgBackendResponseTime":208});});</script>
</body>
</html>

View File

@ -1,56 +1,43 @@
import fs from "fs";
import path from 'path';
import sendPostMastodon, {
randomIntFromInterval,
findFirstImageInContent,
findPictureAndSendPost,
} from './utils.mjs'
getArticlesFromDaysInRssFeed,
makeTitleContentFromRss,
parseRssFeed,
folderBlogPostsPreview
} from "./utils.mjs";
const __dirname = path.resolve();
const afis_rss_feed ='';
const days_back_in_rss_feed= 7;
let reallySendPost = false;
// reallySendPost = true;
const afis_rss_feed_url = 'https://afis.org/rss.xml';
const days_back_in_rss_feed = 7;
async function postLink() {
console.log("envoi de post des articles afis sciences publiés depuis " + days_back_in_rss_feed + " jours par le compte tykayn")
function getArticlesFromDaysInRssFeed(rss_feed , days=7) {
return rss_feed;
}
function makeTitleContentFromRss(rss_feed) {
let content = ''
return content;
}
function postLink() {
console.log("envoi de post des articles afis sciences publiés depuis "+days_back_in_rss_feed+" jours par le compte tykayn")
console.log(postObject)
let contentOfPost = 'Articles des '+days_back_in_rss_feed+' derniers jours sur le site web de l\'AFIS: '+ makeTitleContentFromRss(getArticlesFromDaysInRssFeed(afis_rss_feed))
let parsedFeed = await parseRssFeed(afis_rss_feed_url)
let articles = await getArticlesFromDaysInRssFeed(parsedFeed, days_back_in_rss_feed)
console.log('articles', articles)
let contentOfPost = 'Articles des ' + days_back_in_rss_feed + ' derniers jours sur le site web de l\'AFIS: \n'
+ makeTitleContentFromRss(articles)
let configPost = {
author: 'afis91',
website: 'afis.org',
slug: postObject.post_name,
postObject,
folder_image: folderBlogPostsPreview,
image: findFirstImageInContent(afis_rss_feed),
// image : 'afis_post_' + randomIntFromInterval(1 , 1) + '.jpg',
// disable_slugify: true,
slug: "afis_picture",
content_type: "text/markdown",
folder_image: process.cwd() + '/assets/',
image: "afis_picture_of_the_day.jpg",
message: `# ${contentOfPost}
* #afis #science #pseudoScience`,
reallySendPost
#afis #science #pseudoScience #hebdo`,
}
console.log("configPost.message", configPost.message)
console.log("configPost.image", configPost.image)
findPictureAndSendPost(postObject.content.rendered, configPost)
console.log("post ID: ", postObject.ID)
// console.log('process.cwd() + \'/assets/blog_posts_medias/\'', process.cwd() + '/assets/blog_posts_medias/')
sendPostMastodon(configPost)
}
postLink();

View File

@ -7,7 +7,8 @@ import https from 'https';
let local_node_env_conf = dotenv.config()
const myArgs = process.argv.slice(2);
let reallySendPost = hasCliArgument('--force');
export const reallySendPost = hasCliArgument('--force');
export const folderBlogPostsPreview = process.cwd() + '/assets/blog_posts_medias/'
export function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min) | 1
@ -25,12 +26,14 @@ export let defaultConfigMasto = {
visibility: 'public',
language: 'fr',
sensitive: false,
disable_slugify:false,
reallySendPost,
image: '',
folder_image: process.cwd() + '/assets/blog_posts_medias/',
message: "Hey coucou! on est le" + nowDate,
scheduled_at: "",
content_type: "text/markdown",
scheduled_at_bool: false,
content_type: "text/markdown",
website: 'qzine',
slug: 'default_post_title',
postObject : {},
@ -58,7 +61,10 @@ export default function sendPostMastodon(config) {
// console.log("sendPostMastodon config", config)
if (!config.reallySendPost) {
console.log("\n =========== le message ne sera PAS réellement posté sur le compte @" + config.author + "@" + process.env.INSTANCE_MASTODON + " =========== \n")
console.log("\n\n =========== le message ne sera PAS réellement posté sur le compte @" + config.author + "@" + process.env.INSTANCE_MASTODON + " =========== \n")
console.log('configPost.folder_image', config.folder_image)
console.log('config', config)
} else {
console.log(" ")
@ -92,6 +98,7 @@ export default function sendPostMastodon(config) {
* envoi sans fichier joint
*/
if (!config.image) {
console.log('pas d image dans la config')
if (config.reallySendPost) {
@ -112,9 +119,9 @@ export default function sendPostMastodon(config) {
else if (config.image) {
var id;
console.log("envoi du média", config.image)
console.log("envoi du média", config.folder_image +config.image)
// upload new media
return masto.post('media', {file: fs.createReadStream(config.image)})
return masto.post('media', {file: fs.createReadStream(config.folder_image +config.image)})
.then(resp => {
id = resp.data.id;
params.media_ids = [id]
@ -268,7 +275,7 @@ export function downloadImage(url, filepath) {
* @returns {Promise<Object>}
* @constructor
*/
export function CropPictue(pictureName, width = 500, height = 300) {
export function CropPicture(pictureName, width = 500, height = 300) {
return sharp(pictureName)
@ -301,18 +308,21 @@ export function getRandomLinkGeneral(tkpostsjson) {
export function findPictureAndSendPost(postContent, configPost){
let firstPictureSource = findFirstImageInContent(postContent);
let filePathImage = `${configPost.folder_image}_${configPost.website}_media_post_${slugify(configPost.slug)}.jpg`
let filePathForDownloadedImage = `${configPost.folder_image}_${configPost.website}_media_post_${slugify(configPost.slug)}.jpg`
if (firstPictureSource) {
console.log("firstPictureSource found", firstPictureSource)
// check if picture already exist
console.log('on envoie le média et l image : ' , filePathImage)
downloadImage(firstPictureSource, filePathImage)
console.log('on envoie le média et l image : ' , filePathForDownloadedImage)
downloadImage(firstPictureSource, filePathForDownloadedImage)
.then((res) => {
// suite du poste avec upload d'image
console.log('média téléchargé, on envoie le post')
configPost.image = filePathImage;
configPost.image = filePathForDownloadedImage;
sendPostMastodon(configPost)
@ -347,4 +357,58 @@ export function hasCliArgument(argument){
console.log('myArgs: ', myArgs);
return myArgs.indexOf(argument) !== -1
}
}
import Parser from 'rss-parser';
let parser = new Parser();
/**
* fetch and return a parsed rss feed
* @param url
* @returns {Promise<*>}
*/
export async function parseRssFeed(url){
let parsedFeed = await parser.parseURL(url);
console.log(parsedFeed.title);
parsedFeed.items.forEach((item) => {
console.log(item.title);
});
return parsedFeed
}
/**
* get a subset of rss parsed items
* @param parsedRssFeed
* @param days
* @returns {T[]}
*/
export function getArticlesFromDaysInRssFeed(parsedRssFeed , days=7) {
// return parsedRssFeed.items.splice(0,days);
return parsedRssFeed.items.splice(0,6);
}
export function makeTitleContentFromRss(parsedFeed) {
let content = ''
let counter = 0;
if (!parsedFeed.length) {
return '';
}
parsedFeed.forEach((item) => {
// if (!counter) {
// console.log('first item', item)
// }
let cleanedTitle= item.title.replace('[','').trim()
cleanedTitle= cleanedTitle.replace(']','').trim()
content += `\n* [${cleanedTitle}](${item.link}) `;
content += `\n ${item.isoDate.substring(0,10)} : ${item.contentSnippet.split('\n')[0]} \n`;
counter++;
});
return content;
}

View File

@ -20,6 +20,7 @@
"node-fs": "^0.1.7",
"nodemon": "^2.0.19",
"oauth": "^0.9.15",
"rss-parser": "^3.12.0",
"sqlite3": "^5.0.8",
"squint-cli": "^2.1.4",
"webpage": "^0.3.0"

6865
yarn.lock

File diff suppressed because it is too large Load Diff