├── nasa-image-of-the-day.jpg ├── .github └── workflows │ └── flat.yaml ├── postprocess.ts ├── LICENSE ├── data.json └── README.md /nasa-image-of-the-day.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/githubocto/flat-demo-NASA-photo-of-the-day/HEAD/nasa-image-of-the-day.jpg -------------------------------------------------------------------------------- /.github/workflows/flat.yaml: -------------------------------------------------------------------------------- 1 | name: Flat 2 | 3 | on: 4 | push: 5 | paths: 6 | - .github/workflows/flat.yml # Only run a new workflow every time this file (flat.yaml) file changes 7 | workflow_dispatch: 8 | schedule: 9 | - cron: '0 0 1 * *' # run once a month 10 | 11 | jobs: 12 | scheduled: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Setup deno 16 | uses: denoland/setup-deno@main 17 | with: 18 | deno-version: v1.x 19 | - name: Check out repo 20 | uses: actions/checkout@v2 21 | - name: Fetch data 22 | uses: githubocto/flat@v3 23 | with: 24 | http_url: https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY # The data to fetch every day 25 | downloaded_filename: data.json # The http_url gets saved and renamed in our repository as data.json 26 | postprocess: postprocess.ts # A postprocessing javascript or typescript file written in Deno 27 | 28 | 29 | -------------------------------------------------------------------------------- /postprocess.ts: -------------------------------------------------------------------------------- 1 | // Helper library written for useful postprocessing tasks with Flat Data 2 | // Has helper functions for manipulating csv, txt, json, excel, zip, and image files 3 | // You can test this script locally on your computer by runinng `deno run -A --unstable postprocess.ts data.json` 4 | import { readJSON, readImageFromURL, writeImage } from 'https://deno.land/x/flat@0.0.14/mod.ts' 5 | 6 | // Get the data filename as the first argument 7 | const filename = Deno.args[0] 8 | const data = await readJSON(filename) 9 | const imageURL = data.url // fetch the URL key in the json 10 | 11 | // Postprocess steps 12 | 13 | // Case 1 it is a normal image 14 | if (!imageURL.startsWith('https://www.youtube.com')) { 15 | const image = await readImageFromURL(imageURL) // fetch the image 16 | await writeImage(image.bytes, './nasa-image-of-the-day.jpg') // create a jpg file 17 | } 18 | // Case 2 it is a link to youtube 19 | else { 20 | console.log("Today has no image, but a link to youtube: ", imageURL) 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 GitHub OCTO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /data.json: -------------------------------------------------------------------------------- 1 | {"date":"2025-11-30","explanation":"If you could stand on Titan -- what would you see? The featured color view from Titan gazes across an unfamiliar and distant landscape on Saturn's largest moon. The scene was recorded by ESA's Huygens probe in 2005 after a 2.5-hour descent through a thick atmosphere of nitrogen laced with methane. Bathed in an eerie orange light at ground level, rocks strewn about the scene could well be composed of water and hydrocarbons frozen solid at an inhospitable temperature of negative 179 degrees C. The large light-toned rock below and left of center is only about 15 centimeters across and lies 85 centimeters away. The saucer-shaped spacecraft is believed to have penetrated about 15 centimeters into a place on Titan's surface that had the consistency of wet sand or clay. Huygen's batteries enabled the probe to take and transmit data for more than 90 minutes after landing. Titan's bizarre chemical environment may bear similarities to planet Earth's before life evolved.","hdurl":"https://apod.nasa.gov/apod/image/2511/Titan_Huygens_960.jpg","media_type":"image","service_version":"v1","title":"The Surface of Titan from Huygens","url":"https://apod.nasa.gov/apod/image/2511/Titan_Huygens_960.jpg"} 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flat Data Demo: NASA Image of the Day 2 | 3 | This demo is part of a larger Flat Data project created by [GitHub OCTO](https://octo.github.com/). Read more about the project [here](https://octo.github.com/projects/flat-data). 4 | 5 | ## What this demo does 6 | 7 | This repository uses a [Flat Data Action](https://github.com/githubocto/flat) to fetch a JSON file with information about [NASA's image of the day](https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY) every day at 8 am UTC. Using a postprocessing script, Flat grabs the image URL within the JSON data and downloads the image as well. 8 | 9 | Inside `.github/workflows/flat.yaml`: 10 | ```yaml 11 | - name: Fetch data 12 | uses: githubocto/flat@v3 13 | with: 14 | http_url: https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY # The data to fetch every day 15 | downloaded_filename: data.json # The http_url gets saved and renamed in our repository as data.json 16 | postprocess: postprocess.ts # A postprocessing javascript or typescript file written in Deno 17 | ``` 18 | 19 | diagram 20 | 21 | ## Postprocessing 22 | 23 | Refer to the [Flat postprocessing library](https://github.com/githubocto/flat-postprocessing) for more helper functions and examples for writing postprocessing scripts. 24 | 25 | ## License 26 | 27 | [MIT](LICENSE) 28 | --------------------------------------------------------------------------------