This project syncs data from the v4 Google Sheets API.
There are a few static streams ("file_metadata"
, "spreadsheet_metadata"
, "sheet_metadata"
,
"sheets_loaded"
) and any number of dynamic streams. There’s one dynamic stream per sheet in the
one Google Sheets Doc.
import sys
import json
import argparse # unused import
import singer
from singer import metadata, utils
from tap_google_sheets.client import GoogleClient
from tap_google_sheets.discover import discover
from tap_google_sheets.sync import sync
LOGGER = singer.get_logger()
This is a typical OAuth2 tap. So in a config file we expect the following keys.
OAuth Related:
client_id
client_secret
refresh_token
Tap related:
spreadsheet_id
start_date
user_agent
REQUIRED_CONFIG_KEYS = [
'client_id',
'client_secret',
'refresh_token',
'spreadsheet_id',
'start_date',
'user_agent'
]
Creates a Singer Catalog and writes it to STDOUT
def do_discover(client, spreadsheet_id):
Inputs:
client
spreadsheet_id
Returns:
Side Effects:
LOGGER.info('Starting discover')
catalog = discover(client, spreadsheet_id)
json.dump(catalog.to_dict(), sys.stdout, indent=2)
LOGGER.info('Finished discover')
Read a config, then run discovery mode or sync mode
@singer.utils.handle_top_exception(LOGGER)
def main():
parsed_args = singer.utils.parse_args(REQUIRED_CONFIG_KEYS)
with GoogleClient(parsed_args.config['access_token'],
parsed_args.config['user_agent']) as client:
state = {}
if parsed_args.state:
state = parsed_args.state
config = parsed_args.config
spreadsheet_id = config.get('spreadsheet_id')
if parsed_args.discover:
do_discover(client, spreadsheet_id)
elif parsed_args.catalog:
sync(client=client,
config=config,
catalog=parsed_args.catalog,
state=state)
Unused
if __name__ == '__main__':
main()