From 81c912534429977a10cc6f470f200a53625336bc Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Fri, 24 May 2024 15:02:24 +0200 Subject: [PATCH] add script to get Le Monde of the day --- lemonde.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lemonde.js diff --git a/lemonde.js b/lemonde.js new file mode 100644 index 0000000..df372ca --- /dev/null +++ b/lemonde.js @@ -0,0 +1,53 @@ +// open https://journal.lemonde.fr, hit f12 and find GetPublicationContentItems complete url + +var url = "https://lmo-lmo-production-cdn.twipecloud.net/lmo/lmo/contentPackages/3761/GetPublicationContentItems-5274.json?v=20240524113722&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHBzOi8vbG1vLWxtby1wcm9kdWN0aW9uLWNkbi50d2lwZWNsb3VkLm5ldC9sbW8vbG1vL2NvbnRlbnRQYWNrYWdlcy8zNzYxLyoiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE3MTY1NTYxOTF9LCJJcEFkZHJlc3MiOnsiQVdTOlNvdXJjZUlwIjoiMC4wLjAuMC8wIn0sIkRhdGVHcmVhdGVyVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNzE2NTU0MzMxfX19XX0_&Signature=qXAEoL6W8UYp1zrq7x1hMPyxTW1NQnyrTB9AJzSRtAUjhpNgd3TQ5kZ4Ma9qndRpEmX4emYp16sEx4TMI1Jq-Bhv~-y47QUUMj7codXTxdMhLd3-tVLb6oftQOA2cmpjjx1VY3fO2gc8DHTQSvFGsCpnOBMHZDCODjS2xCOPnps_&Key-Pair-Id=APKAJZKKWCWU2JPGEHQQ"; +var output = ""; +var toc = ""; + +function sanitize(s) +{ + return s.replace(/<[^>]*>?/gm, ''); +} + +fetch(url) +.then(r => r.json()) +.then(publication => + { + publication + .Content + .filter(article => article.Category == "Le Monde") + .sort( (a,b) => a.PageNumber - b.PageNumber) + .forEach(article => + { + var contentitem = article.ContentItem.find(i => i.ContentType == "text/xml"); + var title = contentitem.Title; + if (title) + { + title = sanitize(title); + var category = sanitize(contentitem.SubTitle).trim(); + var id = article.ContentID; + var page = article.PageNumber; + + if (page > 1) + { + toc += "" + title + "" + if (category) + { + toc += " (" + category + ")"; + } + toc += "
"; + } + + output += "

" + title + "

"; + if (category) + { + output += "

" + category + "

"; + } + output += contentitem.HtmlText; + } + }); + console.log("Le Monde" + toc + output + ""); + } +); + +