]>
Commit | Line | Data |
---|---|---|
89643ba6 JH |
1 | from singer.catalog import Catalog, CatalogEntry, Schema |
2 | from tap_google_sheets.schema import get_schemas, STREAMS | |
3 | ||
4 | ||
5 | def 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 | |
99424fee JH |
13 | for mdt in mdata: |
14 | table_key_properties = mdt.get('metadata', {}).get('table-key-properties') | |
89643ba6 JH |
15 | if table_key_properties: |
16 | key_properties = table_key_properties | |
99424fee | 17 | |
89643ba6 JH |
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 |