• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Google Apps Script that publishes a Google Sheet to Amazon S3 as a JSON file. Auto-updates on edit & maintains data types. Creates an array of objects keyed by column header.

logo google-sheet-s3

A Google Apps Script that publishes a Google Sheet to Amazon S3 as a JSON file. Creates an array of objects keyed by column header, maintaining data types like numbers and booleans.

For example, it turns a spreadsheet like this:

Example spreadsheet

Into an S3-hosted JSON file like this:

[
  {
    "headline": "Lorem ipsum dolor sit amet",
    "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tristique senectus et netus et malesuada fames ac turpis egestas. Purus gravida quis blandit turpis cursus in. ",
    "author": "hliddiard",
    "post_time": "2022-12-28T23:44:55.000Z",
    "publish": true
  },
  {
    "headline": "Ut enim ad minim veniam",
    "body": "Eget lorem dolor sed viverra. Ipsum suspendisse ultrices gravida dictum fusce ut.",
    "author": "jdoe",
    "post_time": "2022-12-29T02:20:01.000Z",
    "publish": true
  },
  {
    "headline": "Duis aute irure dolor",
    "body": "Aliquam id diam maecenas ultricies mi eget mauris pharetra. Sit amet dictum sit amet justo donec enim diam vulputate. Massa ultricies mi quis hendrerit. Rutrum quisque non tellus orci.",
    "author": "jdoe",
    "post_time": "2022-12-29T17:10:22.000Z",
    "publish": true
  },
  {
    "headline": "Excepteur sint occaecat cupidatat non proident",
    "body": "Pellentesque habitant morbi tristique senectus et netus et. Est ultricies integer quis auctor elit sed vulputate. Donec et odio pellentesque diam volutpat commodo sed. Sapien et ligula ullamcorper malesuada proin. Accumsan sit amet nulla facilisi morbi tempus.",
    "author": "hliddiard",
    "post_time": "2022-12-29T19:45:05.000Z",
    "publish": false
  }
]

Get the add-on here on the Chrome Web Store.

2023 update: Google has unpublished the add-on for not being up-to-date with their latest developer requirements. I'm working on figuring out the best way to let others install/use it easily. In the meantime, you can use it by following the development setup instructions below.

Why?

Use case

"I want to display simple, structured, spreadsheet-like, publicly accessible data on a website (possibly with thousands of simultaneous visitors) that is easily updatable (possibly by multiple people at once) without the overhead and time of coding, deploying, and maintaining a database, API, and admin interface."

Examples

Staff directory list, restaurant menu items listing, sports team standings page, live blog.

Why not [alternative]?

  • Doesn't require OAuth like the official Google Sheets API (no good for anonymous data viewing).
  • Not using deprecated APIs like Tabletop.js that could suffer an untimely disappearance at the whims of Google.
  • Doesn't require an intermediary web application like WSJ uses/used.
  • Not an alternative service like Airtable that is powerful but costs πŸ’°πŸ’°πŸ’°.
  • Not slow at returning data like Google Apps Script Web Apps seem to be. (If you're okay with 2000ms response times, this solution is easier because it doesn't involve S3. S3 response times tend to be 10-20x faster.)

Setup

We need to get an Amazon Web Services (AWS) S3 bucket and your Google Sheet to talk to each other, so there are two parts to this setup: one for AWS, and one for the spreadsheet.

AWS setup

  1. If you don't have one already, create an Amazon AWS account.
  2. If you don't have one already, create an AWS S3 bucket.
  3. If you don't have one already, create an IAM user that has write permission to your S3 bucket. You'll need these credentials later.
  4. Add a bucket policy that enables public viewing of the published JSON. To enable, go to your S3 Management Console, click your bucket's name > Permissions tab > Bucket policy > enter your policy (sample to paste below) > click Save.
  5. If you're going to be accessing the published JSON data from a web browser, you will also need to add a CORS policy to your S3 bucket that allows GET requests from whatever origin (domain name) you want to access your data from. To add a policy, go to your S3 Management Console, click your bucket's name > Permissions tab > CORS configuration > enter your policy (sample to paste below) > click Save.

Sample bucket policy

This configuration is what I imagine most people using this add-on will want. It allows public access of the data stored in your Google Sheet, but not public write access.

Replace the text "PUT-YOUR-BUCKET-NAME-HERE" with your bucket's name.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::PUT-YOUR-BUCKET-NAME-HERE/*"
        }
    ]
}

Sample CORS policy

This configuration will allow any web page on the internet to access your sheet's data. You may not want that. You can modify the line <AllowedOrigin>*</AllowedOrigin> and replace the asterisk with your own hostname; e.g. the domain name from which you will be making Ajax requests for the sheet's JSON.

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>

Google Sheet setup

How to use the add-on after completing the above AWS setup.

  1. Create or open an existing Google Sheet.
  2. Format the sheet so that the first row contains the column headers you want your JSON objects to have as properties. Example: Example
  3. Install and enable the add-on.
  4. In the spreadsheet's menu, go to Add-ons > Publish to S3 > Configure...
  5. Fill in the S3 bucket name, folder path within the bucket where you want data stored (leave blank for top level), and your AWS credentials that allow write access to the bucket.
  6. Click "Save". The S3 URL of your JSON-ified spreadsheet will be shown.

Did I miss something in these instructions? Not working as expected? Feel free to file an issue.

Any time you want to update the published JSON, go to menu item Add-ons > Publish to S3 > Publish.

Usage notes

  • The JSON file's filename is taken from the spreadsheet ID, so the spreadsheet can be safely renamed without breaking the URL.
  • The add-on only looks at the sequentially first sheet tab (called "Sheet1" by default). It won't publish or respond to changes on other tabs.
  • The add-on will ignore columns that don't have a value in the header (row 1) of the spreadsheet.
  • The add-on will ignore empty rows, skipping over them to the next row with values.
  • A blank cell in a row is represented in the JSON as null. So if you have a column that could have missing or optional values, be sure to handle the null value in your consuming code.

Development setup instructions

  1. Create a new Google Apps Script with files whose names and content matches the ones in this repo (minus this readme).
  2. In the menu bar, click Deploy > Test Deployments.
  3. On the left sidebar, Select type > Editor Add-on.
  4. Under Editor Add-on, press Create new test.
  5. Version: Latest code, Config: Installed and enabled, Test document: (select a spreadsheet to use)
  6. Press Done.
  7. Select the saved test and press Execute.

Developement links for version published to Chrome Web Store

These links are not publicly accessible – please do not request access. They're only for my personal reference to develop the script. If you'd like to develop on this script yourself, follow the instructions above to set up a development environment.

Credits

Logo attribution

More Repositories

1

text-diff

Visual JavaScript text diff library. CommonJS module created from https://code.google.com/p/google-diff-match-patch/.
JavaScript
146
star
2

stream-editor

A web tool for interactively using and chaining command-line text manipulation utilities like sed, grep, and awk.
HTML
25
star
3

slack-meetups

Slack bot that randomly pairs users in a Slack channel for 1:1 meetups. Meet new, interesting people in your company, club, or group!
Python
18
star
4

skry

Extendable CMS for small news organizations following decoupled CMS design paradigm. Built on Django Rest Framework. Dynamic image resizing, revision history, fully exposable models API.
Python
16
star
5

driving-time-heatmap

Input an origin point, generate a heatmap of driving times to surrounding areas at different times of day. πŸš— ⏱ πŸ”₯ πŸ—Ί
JavaScript
10
star
6

harmontown-search

Search all transcripts from the Harmontown podcast. Transcription powered by OpenAI's Whisper model. Search powered by Typesense.
TypeScript
7
star
7

google-diff-match-patch

Automatically exported from code.google.com/p/google-diff-match-patch
Python
4
star
8

type-emoji

The no-nonsense emoji search keyboard. Search for and copy emoji quickly.
JavaScript
4
star
9

flight-status-dashboard

Simple command line UI to display the progress of your flight.
JavaScript
3
star
10

sepalnote

Hierarchical note taking webapp. Django/PostgreSQL + AngularJS. (under development)
Python
3
star
11

monitor404

Easy-to-configure service for logging and notification of HTTP 404 errors.
HTML
3
star
12

google-sheets-json

NPM package to easily get data from public Google Sheets and format the messy API response in a pretty, usable way.
JavaScript
3
star
13

react-kofi-overlay

A React component for accepting donations though Ko-fi without leaving your website
TypeScript
3
star
14

spectacle

Web viewer for circular videos – such as those produced by Snap Inc.'s Spectacles smartglasses – using gyroscope data from DeviceOrientation events. This library is not affiliated with or endorsed by Snap, Inc.
JavaScript
2
star
15

simple-video-chat

[WIP] Dead simple video chat using WebRTC and the SimpleWebRTC library. Idea is to make it simple enough for anyone to use easily – no extraneous user interface stuff that every video chat app seems to have.
JavaScript
2
star
16

smarthome

Collection of my smarthome-related scripts
JavaScript
2
star
17

mailpdf

Online service to mail a PDF document anywhere in the U.S. under 60 seconds.
JavaScript
2
star
18

console.console

A method on `console` for when you need consolation that you're doing ok. `console.console()`
JavaScript
2
star
19

spekti

Type the name of a TV show at the command line and start watching the latest episode within 10 seconds. πŸ“Ί Uses torrent search scraping, TVDB API, and WebTorrent CLI.
JavaScript
1
star
20

bionic-ears

Experimenting with using the web audio API to give you super hearing while filtering out transient noise.
JavaScript
1
star
21

gifdatabase

The internet's finest animated GIF search. (until Giphy came around... someone give me $150 million in venture capital?)
Python
1
star
22

my-commute-dashboard

Visualize when the trains are arriving along my personal commute and when to leave to catch them. πŸš†β³
JavaScript
1
star
23

cs35l

UCLA Winter 2015 CS 35L (Software Construction Laboratory) labs and homework.
Assembly
1
star
24

bottom-nav-visibility-change

Event listener to detect when the visibility of the Mobile Safari bottom navigation bar has changed.
HTML
1
star
25

kikl

The link shortener for easy to type and remember URLs. E.g., kikl.co/goofy-lemur instead of bit.ly/1QyEygk
Python
1
star
26

yagsa

Yet Another Google Spreadsheet API. Get the contents of a Google Sheet in properly-typed JSON, cache the result.
JavaScript
1
star
27

react-live-blog

**Not yet production-ready** React live blog component using good ol' Ajax polling that supports arbitrary embeds and markdown formatting. Works great with a data backend using https://github.com/liddiard/google-sheet-s3
JavaScript
1
star