import * as fs from "node:fs";
import axios from "npm:axios";
import request from "npm:request";
export default async function(interval: Interval) {
const nytCookie = "insert-cookie-here";
const nytCrosswordURLPrefix = "https://www.nytimes.com/svc/crosswords/v2/puzzle/print/";
const rmToken = "insert-bearer-token-here";
const rmFolderGuid = "insert-parent-folder-guid-here";
const rmFilesEndpoint = "https://web.eu.tectonic.remarkable.com/doc/v2/files";
const today = new Date(Date.now());
const month = today.toLocaleString("default", { month: "long" });
var day = today.getDate();
if (day < 10) {
day = "0" + day;
}
const year = today.getFullYear();
const puzzleName = month.substring(0, 3) + day + (year - 2000);
const puzzleFriendlyName = `${month} ${today.getDate()} ${year}`;
const puzzlePDFUrl = nytCrosswordURLPrefix + puzzleName + ".pdf";
console.log("Fetching " + puzzleName + " from " + puzzlePDFUrl + "...");
axios({
method: "get",
url: puzzlePDFUrl,
responseType: "arraybuffer",
responseEncoding: "binary",
headers: {
"Cookie": nytCookie,
"Accept": "/",
"Connection": "keep-alive",
},
})
.then(function(response) {
var rmMetadata = { "parent": rmFolderGuid, "file_name": puzzleFriendlyName };
console.log("Uploading " + puzzleName + " to reMarkable...");
request({
url: rmFilesEndpoint,
method: "POST",
headers: {
"Content-Type": "application/pdf",
"Accept": "*/*",
"Authorization": rmToken,
"rm-meta": btoa(JSON.stringify(rmMetadata)),
"rm-source": "WebLibrary",
"Content-Disposition": `file; filename="${puzzleName}.pdf"`,
},
encoding: null,
body: response.data,
}, (error, response, body) => {
if (error) {
console.log("Failed: ", error);
} else {
console.log(JSON.parse(response.body.toString()));
}
});
});
}