├── .github └── workflows │ └── flat.yaml ├── LICENSE ├── README.md ├── mobile-connectivity.csv ├── mobile-connectivity.xlsx └── postprocess.ts /.github/workflows/flat.yaml: -------------------------------------------------------------------------------- 1 | name: flat 2 | on: 3 | schedule: 4 | - cron: "0 0 1 * *" # run once a month 5 | workflow_dispatch: {} 6 | push: 7 | paths: 8 | - .github/workflows/flat.yml # Only run a new workflow every time this file (flat.yaml) file changes 9 | jobs: 10 | scheduled: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Setup deno 14 | uses: denoland/setup-deno@main 15 | with: 16 | deno-version: v1.x 17 | - name: Check out repo 18 | uses: actions/checkout@v2 19 | - name: Fetch data 20 | uses: githubocto/flat@v3 21 | with: 22 | http_url: https://www.mobileconnectivityindex.com/widgets/connectivityIndex/excel/MCI_Data_2020.xlsx 23 | downloaded_filename: mobile-connectivity.xlsx # The http_url gets saved and renamed in our repository as this file 24 | postprocess: ./postprocess.ts # A postprocessing javascript or typescript file written in Deno 25 | -------------------------------------------------------------------------------- /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: XLSX to CSV 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 XLSX file from an http endpoint every 15 minutes. Using a postprocessing script, Flat converts the XLSX file to a CSV file. 8 | 9 | Inside `.github/workflows/flat.yaml`: 10 | ```yaml 11 | - name: Fetch data 12 | uses: githubocto/flat@v3 13 | with: 14 | http_url: https://www.mobileconnectivityindex.com/widgets/connectivityIndex/excel/MCI_Data_2020.xlsx 15 | downloaded_filename: mobile-connectivity.xlsx # The http_url gets saved and renamed in our repository as this file 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 | -------------------------------------------------------------------------------- /mobile-connectivity.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/githubocto/flat-demo-xlsx/59e89570744109c6462f761dad52c7553b7fc312/mobile-connectivity.xlsx -------------------------------------------------------------------------------- /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 | import { xlsx, readXLSX, writeCSV } from "https://deno.land/x/flat@0.0.14/mod.ts"; 4 | 5 | // Get the downloaded_filename as the first argument 6 | const inputFilename = Deno.args[0]; 7 | const outputFilename = inputFilename.replace(".xlsx", ".csv"); 8 | 9 | // read about what the xlsx library can do here: https://github.com/SheetJS/sheetjs 10 | 11 | const workbook = await readXLSX(inputFilename); 12 | const sheetData = workbook.Sheets[workbook.SheetNames[2]]; 13 | const csvString = await xlsx.utils.sheet_to_csv(sheetData); // can use to_json, to_txt, to_html, to_formulae 14 | 15 | // write to csv 16 | await writeCSV(outputFilename, csvString); 17 | --------------------------------------------------------------------------------