diff options
Diffstat (limited to 'tap_google_sheets/__init__.py')
-rw-r--r-- | tap_google_sheets/__init__.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tap_google_sheets/__init__.py b/tap_google_sheets/__init__.py new file mode 100644 index 0000000..f97d4b8 --- /dev/null +++ b/tap_google_sheets/__init__.py | |||
@@ -0,0 +1,57 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | import sys | ||
4 | import json | ||
5 | import argparse | ||
6 | import singer | ||
7 | from singer import metadata, utils | ||
8 | from tap_google_sheets.client import GoogleClient | ||
9 | from tap_google_sheets.discover import discover | ||
10 | from tap_google_sheets.sync import sync | ||
11 | |||
12 | LOGGER = singer.get_logger() | ||
13 | |||
14 | REQUIRED_CONFIG_KEYS = [ | ||
15 | 'client_id', | ||
16 | 'client_secret', | ||
17 | 'refresh_token', | ||
18 | 'spreadsheet_id', | ||
19 | 'start_date', | ||
20 | 'user_agent' | ||
21 | ] | ||
22 | |||
23 | def do_discover(client, spreadsheet_id): | ||
24 | |||
25 | LOGGER.info('Starting discover') | ||
26 | catalog = discover(client, spreadsheet_id) | ||
27 | json.dump(catalog.to_dict(), sys.stdout, indent=2) | ||
28 | LOGGER.info('Finished discover') | ||
29 | |||
30 | |||
31 | @singer.utils.handle_top_exception(LOGGER) | ||
32 | def main(): | ||
33 | |||
34 | parsed_args = singer.utils.parse_args(REQUIRED_CONFIG_KEYS) | ||
35 | |||
36 | with GoogleClient(parsed_args.config['client_id'], | ||
37 | parsed_args.config['client_secret'], | ||
38 | parsed_args.config['refresh_token'], | ||
39 | parsed_args.config['user_agent']) as client: | ||
40 | |||
41 | state = {} | ||
42 | if parsed_args.state: | ||
43 | state = parsed_args.state | ||
44 | |||
45 | config = parsed_args.config | ||
46 | spreadsheet_id = config.get('spreadsheet_id') | ||
47 | |||
48 | if parsed_args.discover: | ||
49 | do_discover(client, spreadsheet_id) | ||
50 | elif parsed_args.catalog: | ||
51 | sync(client=client, | ||
52 | config=config, | ||
53 | catalog=parsed_args.catalog, | ||
54 | state=state) | ||
55 | |||
56 | if __name__ == '__main__': | ||
57 | main() | ||