add script to get Le Monde of the day

This commit is contained in:
quenousimporte 2024-05-24 15:02:24 +02:00
parent a7d045b484
commit 81c9125344
1 changed files with 53 additions and 0 deletions

53
lemonde.js Normal file
View File

@ -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 += "<a href=\"#" + id + "\">" + title + "</a>"
if (category)
{
toc += " (" + category + ")";
}
toc += "<br>";
}
output += "<h1 id=\"" + id + "\">" + title + "</h1>";
if (category)
{
output += "<p><em>" + category + "</em></p>";
}
output += contentitem.HtmlText;
}
});
console.log("<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>Le Monde</title></head><body>" + toc + output + "</body></html>");
}
);