Skip to content

Instantly share code, notes, and snippets.

@rotespferd
Created April 10, 2022 18:47
Show Gist options
  • Save rotespferd/3c8bc0ba48e303e826118d56547bba9a to your computer and use it in GitHub Desktop.
Save rotespferd/3c8bc0ba48e303e826118d56547bba9a to your computer and use it in GitHub Desktop.
Download todays cover of the New York Times
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