Created
April 10, 2022 18:47
-
-
Save rotespferd/3c8bc0ba48e303e826118d56547bba9a to your computer and use it in GitHub Desktop.
Download todays cover of the New York Times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { format } from "https://deno.land/std@0.134.0/datetime/mod.ts"; | |
const download = async (url: string, filename: string) => { | |
const data = (await fetch(url)).arrayBuffer(); | |
return Deno.writeFile(filename, new Uint8Array(await data)); | |
}; | |
const outputDir = Deno.args[0]; | |
const date = new Date(); | |
const outputFile = `${outputDir}/nyt_cover_${format(date, "yyyy-MM-dd")}.pdf`; | |
const baseUrl = "https://static01.nyt.com/images"; | |
const dateUrl = `${baseUrl}/${format(date, "yyyy/MM/dd")}`; | |
const downloadUrl = `${dateUrl}/nytfrontpage/scan.pdf`; | |
console.log(`Download ${downloadUrl} to ${outputDir}`); | |
download(downloadUrl, outputFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment