aboutsummaryrefslogtreecommitdiffhomepage
path: root/tap_google_sheets/discover.py
diff options
context:
space:
mode:
Diffstat (limited to 'tap_google_sheets/discover.py')
-rw-r--r--tap_google_sheets/discover.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tap_google_sheets/discover.py b/tap_google_sheets/discover.py
new file mode 100644
index 0000000..6477a5f
--- /dev/null
+++ b/tap_google_sheets/discover.py
@@ -0,0 +1,26 @@
1from singer.catalog import Catalog, CatalogEntry, Schema
2from tap_google_sheets.schema import get_schemas, STREAMS
3
4
5def discover(client, spreadsheet_id):
6 schemas, field_metadata = get_schemas(client, spreadsheet_id)
7 catalog = Catalog([])
8
9 for stream_name, schema_dict in schemas.items():
10 schema = Schema.from_dict(schema_dict)
11 mdata = field_metadata[stream_name]
12 key_properties = None
13 for md in mdata:
14 table_key_properties = md.get('metadata', {}).get('table-key-properties')
15 if table_key_properties:
16 key_properties = table_key_properties
17
18 catalog.streams.append(CatalogEntry(
19 stream=stream_name,
20 tap_stream_id=stream_name,
21 key_properties=STREAMS.get(stream_name, {}).get('key_properties', key_properties),
22 schema=schema,
23 metadata=mdata
24 ))
25
26 return catalog