-
Notifications
You must be signed in to change notification settings - Fork 3
/
postprocess.ts
21 lines (18 loc) · 928 Bytes
/
postprocess.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Helper library written for useful postprocessing tasks with Flat Data
// Has helper functions for manipulating csv, txt, json, excel, zip, and image files
// You can test this script locally on your computer by runinng `deno run -A --unstable postprocess.ts data.json`
import { readJSON, readImageFromURL, writeImage } from 'https://deno.land/x/flat@0.0.14/mod.ts'
// Get the data filename as the first argument
const filename = Deno.args[0]
const data = await readJSON(filename)
const imageURL = data.url // fetch the URL key in the json
// Postprocess steps
// Case 1 it is a normal image
if (!imageURL.startsWith('https://www.youtube.com')) {
const image = await readImageFromURL(imageURL) // fetch the image
await writeImage(image.bytes, './nasa-image-of-the-day.jpg') // create a jpg file
}
// Case 2 it is a link to youtube
else {
console.log("Today has no image, but a link to youtube: ", imageURL)
}