├── .github └── workflows │ └── flat.yaml ├── LICENSE ├── README.md ├── data.json ├── nasa-image-of-the-day.jpg └── postprocess.ts /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /data.json: -------------------------------------------------------------------------------- 1 | {"copyright":"Marcella Giulia Pace","date":"2025-05-31","explanation":"On May 7, the Sun setting behind a church bell tower was captured in this filtered and manipulated digital skyscape from Ragusa, Sicily, planet Earth. In this version of the image the colors look bizarre. Still, an intriguing optical illusion known as an afterimage can help you experience the same scene with a more natural looking appearance. To try it, find the sunspots of active region AR4079 grouped near the bottom of the blue solar disk. Relax and stare at the dark sunspot group for about 30 seconds, then close your eyes or shift your gaze to a plain white surface. In a moment an afterimage of the sunset should faintly appear. But the afterimage sunset will have this image's complementary colors and a more normal yellow Sun against a familiar blue sky.","hdurl":"https://apod.nasa.gov/apod/image/2505/Afterimageorizontal.jpeg","media_type":"image","service_version":"v1","title":"Afterimage Sunset","url":"https://apod.nasa.gov/apod/image/2505/Afterimageorizontalcrop.jpeg"} 2 | -------------------------------------------------------------------------------- /nasa-image-of-the-day.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/githubocto/flat-demo-NASA-photo-of-the-day/a68d1feb4b40161a7bb94c075a8dd27c0ea5c893/nasa-image-of-the-day.jpg -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------