Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move landings strategy next to answers #49

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="tap-typeform",
version="1.4.0",
version="1.4.2",
description="Singer.io tap for extracting data from the TypeForm Responses API",
author="bytcode.io",
url="http://singer.io",
Expand Down
62 changes: 23 additions & 39 deletions tap_typeform/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ def get_forms(atx):
LOGGER.info('All forms query')
return atx.client.get_forms()

def get_landings(atx, form_id):
LOGGER.info('All landings query')
return atx.client.get_form_responses(form_id)

def sync_form_definition(atx, form_id):
with singer.metrics.job_timer('form definition '+form_id):
start = time.monotonic()
Expand Down Expand Up @@ -159,11 +155,12 @@ def sync_form(atx, form_id, start_date, token=None, next_page=False):
else:
time.sleep(METRIC_JOB_POLL_SLEEP)

answers_data_rows = []

max_submitted_dt = pendulum.from_timestamp(start_date).isoformat()
max_token = ''

answers_data_rows = []
landings_data_rows = []

for row in data:

max_submitted_dt = row['submitted_at']
Expand All @@ -190,8 +187,28 @@ def sync_form(atx, form_id, start_date, token=None, next_page=False):
"answer": answer_value
})

if 'landings' in atx.selected_stream_ids:
if 'hidden' not in row:
hidden = ''
else:
hidden = json.dumps(row['hidden'])
landings_data_rows.append({
"landing_id": row['landing_id'],
"token": row['token'],
"landed_at": row['landed_at'],
"submitted_at": row['submitted_at'],
"user_agent": row['metadata']['user_agent'],
"platform": row['metadata']['platform'],
"referer": row['metadata']['referer'],
"network_id": row['metadata']['network_id'],
"browser": row['metadata']['browser'],
"hidden": hidden
})

if 'answers' in atx.selected_stream_ids:
write_records(atx, 'answers', answers_data_rows)
if 'landings' in atx.selected_stream_ids:
write_records(atx, 'landings', landings_data_rows)

return response.get('page_count', 0), max_submitted_dt, max_token

Expand Down Expand Up @@ -269,36 +286,6 @@ def get_bookmark_value(state, stream_name, key, default=None):

return bookmark


def sync_landings(atx, form_id):
response = get_landings(atx, form_id)
landings_data_rows = []

for row in response['items']:
if 'hidden' not in row:
hidden = ''
else:
hidden = json.dumps(row['hidden'])

# the schema here reflects what we saw through testing
# the typeform documentation is subtly inaccurate
if 'landings' in atx.selected_stream_ids:
landings_data_rows.append({
"landing_id": row['landing_id'],
"token": row['token'],
"landed_at": row['landed_at'],
"submitted_at": row['submitted_at'],
"user_agent": row['metadata']['user_agent'],
"platform": row['metadata']['platform'],
"referer": row['metadata']['referer'],
"network_id": row['metadata']['network_id'],
"browser": row['metadata']['browser'],
"hidden": hidden
})

write_records(atx, 'landings', landings_data_rows)


def sync_forms(atx):
for form_id in atx.config.get('forms').split(','):
LOGGER.info('form: {} '.format(form_id))
Expand All @@ -307,9 +294,6 @@ def sync_forms(atx):
if 'questions' in atx.selected_stream_ids:
sync_form_definition(atx, form_id)

if 'landings' in atx.selected_stream_ids:
sync_landings(atx, form_id)

should_sync_forms = False
for stream_name in FORM_STREAMS:
should_sync_forms = should_sync_forms or (stream_name in atx.selected_stream_ids)
Expand Down