Skip to content

Commit

Permalink
Test add pad and ignore hidden sheets (#35)
Browse files Browse the repository at this point in the history
* Add pad to columns without data and ignore hidden sheets

* fix error from merge conflict resolution

* remove extra line

Co-authored-by: scott.coleman <scott.coleman@bytecode.io>
Co-authored-by: Kyle Allan <KAllan357@gmail.com>
  • Loading branch information
3 people authored May 24, 2021
1 parent f9c0243 commit 2497387
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tap_google_sheets/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ def colnum_string(num):
return string


def pad_default_effective_values(headers, first_values):
for i in range(len(headers) - len(first_values)):
first_values.append(OrderedDict())


# Create sheet_metadata_json with columns from sheet
def get_sheet_schema_columns(sheet):
sheet_title = sheet.get('properties', {}).get('title')
sheet_json_schema = OrderedDict()
data = next(iter(sheet.get('data', [])), {})
row_data = data.get('rowData', [])
if row_data == []:
# Empty sheet, SKIP
if row_data == [] or len(row_data) == 1:
# Empty sheet or empty first row, SKIP
LOGGER.info('SKIPPING Empty Sheet: {}'.format(sheet_title))
return None, None

# spreadsheet is an OrderedDict, with orderd sheets and rows in the repsonse
headers = row_data[0].get('values', [])
first_values = row_data[1].get('values', [])
# LOGGER.info('first_values = {}'.format(json.dumps(first_values, indent=2, sort_keys=True)))
# Pad first row values with default if null
if len(first_values) < len(headers):
pad_default_effective_values(headers, first_values)

sheet_json_schema = {
'type': 'object',
Expand Down

0 comments on commit 2497387

Please sign in to comment.