Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Sample script for how to load a NYT Crossword onto a reMarkable tablet. More details at https://www.bjmalicoat.com/projects/nytremarkable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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";
// Construct URL for today's Crossword
// e.g. https://www.nytimes.com/svc/crosswords/v2/puzzle/print/Sep0724.pdf
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()));
}
});
});
}
September 9, 2024