本文整理汇总了Python中singer.write_record方法的典型用法代码示例。如果您正苦于以下问题:Python singer.write_record方法的具体用法?Python singer.write_record怎么用?Python singer.write_record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类singer
的用法示例。
在下文中一共展示了singer.write_record方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _sync_contacts_by_company
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def _sync_contacts_by_company(STATE, ctx, company_id):
schema = load_schema(CONTACTS_BY_COMPANY)
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
url = get_url("contacts_by_company", company_id=company_id)
path = 'vids'
with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
with metrics.record_counter(CONTACTS_BY_COMPANY) as counter:
data = request(url, default_contacts_by_company_params).json()
for row in data[path]:
counter.increment()
record = {'company-id' : company_id,
'contact-id' : row}
record = bumble_bee.transform(lift_properties_and_versions(record), schema, mdata)
singer.write_record("contacts_by_company", record, time_extracted=utils.now())
return STATE
示例2: sync_campaigns
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def sync_campaigns(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
schema = load_schema("campaigns")
singer.write_schema("campaigns", schema, ["id"], catalog.get('stream_alias'))
LOGGER.info("sync_campaigns(NO bookmarks)")
url = get_url("campaigns_all")
params = {'limit': 500}
with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
for row in gen_request(STATE, 'campaigns', url, params, "campaigns", "hasMore", ["offset"], ["offset"]):
record = request(get_url("campaigns_detail", campaign_id=row['id'])).json()
record = bumble_bee.transform(lift_properties_and_versions(record), schema, mdata)
singer.write_record("campaigns", record, catalog.get('stream_alias'), time_extracted=utils.now())
return STATE
示例3: get_all_issue_labels
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def get_all_issue_labels(schemas, repo_path, state, mdata):
# https://developer.github.com/v3/issues/labels/
# not sure if incremental key
# 'https://api.github.com/repos/{}/labels?sort=created_at&direction=desc'.format(repo_path)
with metrics.record_counter('issue_labels') as counter:
for response in authed_get_all_pages(
'issue_labels',
'https://api.github.com/repos/{}/labels'.format(repo_path)
):
issue_labels = response.json()
extraction_time = singer.utils.now()
for r in issue_labels:
r['_sdc_repository'] = repo_path
# transform and write release record
with singer.Transformer() as transformer:
rec = transformer.transform(r, schemas, metadata=metadata.to_map(mdata))
singer.write_record('issue_labels', rec, time_extracted=extraction_time)
singer.write_bookmark(state, repo_path, 'issue_labels', {'since': singer.utils.strftime(extraction_time)})
counter.increment()
return state
示例4: get_all_releases
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def get_all_releases(schemas, repo_path, state, mdata):
# Releases doesn't seem to have an `updated_at` property, yet can be edited.
# For this reason and since the volume of release can safely be considered low,
# bookmarks were ignored for releases.
with metrics.record_counter('releases') as counter:
for response in authed_get_all_pages(
'releases',
'https://api.github.com/repos/{}/releases?sort=created_at&direction=desc'.format(repo_path)
):
releases = response.json()
extraction_time = singer.utils.now()
for r in releases:
r['_sdc_repository'] = repo_path
# transform and write release record
with singer.Transformer() as transformer:
rec = transformer.transform(r, schemas, metadata=metadata.to_map(mdata))
singer.write_record('releases', rec, time_extracted=extraction_time)
singer.write_bookmark(state, repo_path, 'releases', {'since': singer.utils.strftime(extraction_time)})
counter.increment()
return state
示例5: get_all_assignees
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def get_all_assignees(schema, repo_path, state, mdata):
'''
https://developer.github.com/v3/issues/assignees/#list-assignees
'''
with metrics.record_counter('assignees') as counter:
for response in authed_get_all_pages(
'assignees',
'https://api.github.com/repos/{}/assignees'.format(repo_path)
):
assignees = response.json()
extraction_time = singer.utils.now()
for assignee in assignees:
assignee['_sdc_repository'] = repo_path
with singer.Transformer() as transformer:
rec = transformer.transform(assignee, schema, metadata=metadata.to_map(mdata))
singer.write_record('assignees', rec, time_extracted=extraction_time)
singer.write_bookmark(state, repo_path, 'assignees', {'since': singer.utils.strftime(extraction_time)})
counter.increment()
return state
示例6: get_all_collaborators
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def get_all_collaborators(schema, repo_path, state, mdata):
'''
https://developer.github.com/v3/repos/collaborators/#list-collaborators
'''
with metrics.record_counter('collaborators') as counter:
for response in authed_get_all_pages(
'collaborators',
'https://api.github.com/repos/{}/collaborators'.format(repo_path)
):
collaborators = response.json()
extraction_time = singer.utils.now()
for collaborator in collaborators:
collaborator['_sdc_repository'] = repo_path
with singer.Transformer() as transformer:
rec = transformer.transform(collaborator, schema, metadata=metadata.to_map(mdata))
singer.write_record('collaborators', rec, time_extracted=extraction_time)
singer.write_bookmark(state, repo_path, 'collaborator', {'since': singer.utils.strftime(extraction_time)})
counter.increment()
return state
示例7: sync_time_filtered
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def sync_time_filtered(entity):
bookmark_property = 'updated_at'
singer.write_schema(entity,
utils.load_schema(entity),
["id"],
bookmark_properties=[bookmark_property])
start = get_start(entity)
logger.info("Syncing {} from {}".format(entity, start))
for row in gen_request(get_url(entity)):
if row[bookmark_property] >= start:
if 'custom_fields' in row:
row['custom_fields'] = transform_dict(row['custom_fields'], force_str=True)
utils.update_state(STATE, entity, row[bookmark_property])
singer.write_record(entity, row, time_extracted=singer.utils.now())
singer.write_state(STATE)
示例8: write_page
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def write_page(self, page):
stream = Context.get_catalog_entry(self.tap_stream_id)
stream_metadata = metadata.to_map(stream.metadata)
extraction_time = singer.utils.now()
for rec in page:
with Transformer() as transformer:
rec = transformer.transform(rec, stream.schema.to_dict(), stream_metadata)
singer.write_record(self.tap_stream_id, rec, time_extracted=extraction_time)
with metrics.record_counter(self.tap_stream_id) as counter:
counter.increment(len(page))
示例9: _sync_contact_vids
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def _sync_contact_vids(catalog, vids, schema, bumble_bee):
if len(vids) == 0:
return
data = request(get_url("contacts_detail"), params={'vid': vids, 'showListMemberships' : True, "formSubmissionMode" : "all"}).json()
time_extracted = utils.now()
mdata = metadata.to_map(catalog.get('metadata'))
for record in data.values():
record = bumble_bee.transform(lift_properties_and_versions(record), schema, mdata)
singer.write_record("contacts", record, catalog.get('stream_alias'), time_extracted=time_extracted)
示例10: sync_contact_lists
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def sync_contact_lists(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
schema = load_schema("contact_lists")
bookmark_key = 'updatedAt'
singer.write_schema("contact_lists", schema, ["listId"], [bookmark_key], catalog.get('stream_alias'))
start = get_start(STATE, "contact_lists", bookmark_key)
max_bk_value = start
LOGGER.info("sync_contact_lists from %s", start)
url = get_url("contact_lists")
params = {'count': 250}
with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
for row in gen_request(STATE, 'contact_lists', url, params, "lists", "has-more", ["offset"], ["offset"]):
record = bumble_bee.transform(lift_properties_and_versions(row), schema, mdata)
if record[bookmark_key] >= start:
singer.write_record("contact_lists", record, catalog.get('stream_alias'), time_extracted=utils.now())
if record[bookmark_key] >= max_bk_value:
max_bk_value = record[bookmark_key]
STATE = singer.write_bookmark(STATE, 'contact_lists', bookmark_key, max_bk_value)
singer.write_state(STATE)
return STATE
示例11: sync_forms
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def sync_forms(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
schema = load_schema("forms")
bookmark_key = 'updatedAt'
singer.write_schema("forms", schema, ["guid"], [bookmark_key], catalog.get('stream_alias'))
start = get_start(STATE, "forms", bookmark_key)
max_bk_value = start
LOGGER.info("sync_forms from %s", start)
data = request(get_url("forms")).json()
time_extracted = utils.now()
with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
for row in data:
record = bumble_bee.transform(lift_properties_and_versions(row), schema, mdata)
if record[bookmark_key] >= start:
singer.write_record("forms", record, catalog.get('stream_alias'), time_extracted=time_extracted)
if record[bookmark_key] >= max_bk_value:
max_bk_value = record[bookmark_key]
STATE = singer.write_bookmark(STATE, 'forms', bookmark_key, max_bk_value)
singer.write_state(STATE)
return STATE
示例12: sync_workflows
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def sync_workflows(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
schema = load_schema("workflows")
bookmark_key = 'updatedAt'
singer.write_schema("workflows", schema, ["id"], [bookmark_key], catalog.get('stream_alias'))
start = get_start(STATE, "workflows", bookmark_key)
max_bk_value = start
STATE = singer.write_bookmark(STATE, 'workflows', bookmark_key, max_bk_value)
singer.write_state(STATE)
LOGGER.info("sync_workflows from %s", start)
data = request(get_url("workflows")).json()
time_extracted = utils.now()
with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
for row in data['workflows']:
record = bumble_bee.transform(lift_properties_and_versions(row), schema, mdata)
if record[bookmark_key] >= start:
singer.write_record("workflows", record, catalog.get('stream_alias'), time_extracted=time_extracted)
if record[bookmark_key] >= max_bk_value:
max_bk_value = record[bookmark_key]
STATE = singer.write_bookmark(STATE, 'workflows', bookmark_key, max_bk_value)
singer.write_state(STATE)
return STATE
示例13: sync_owners
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def sync_owners(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
schema = load_schema("owners")
bookmark_key = 'updatedAt'
singer.write_schema("owners", schema, ["ownerId"], [bookmark_key], catalog.get('stream_alias'))
start = get_start(STATE, "owners", bookmark_key)
max_bk_value = start
LOGGER.info("sync_owners from %s", start)
params = {}
if CONFIG.get('include_inactives'):
params['includeInactives'] = "true"
data = request(get_url("owners"), params).json()
time_extracted = utils.now()
with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
for row in data:
record = bumble_bee.transform(lift_properties_and_versions(row), schema, mdata)
if record[bookmark_key] >= max_bk_value:
max_bk_value = record[bookmark_key]
if record[bookmark_key] >= start:
singer.write_record("owners", record, catalog.get('stream_alias'), time_extracted=time_extracted)
STATE = singer.write_bookmark(STATE, 'owners', bookmark_key, max_bk_value)
singer.write_state(STATE)
return STATE
示例14: setUp
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def setUp(self):
utils.verify_environment_vars()
utils.seed_tap_hubspot_config()
singer.write_bookmark = utils.our_write_bookmark
singer.write_state = utils.our_write_state
singer.write_record = utils.our_write_record
singer.write_schema = utils.our_write_schema
singer.set_offset = set_offset_with_exception
#NB> test accounts must have > 1 companies for this to work
示例15: ad_creative_success
# 需要导入模块: import singer [as 别名]
# 或者: from singer import write_record [as 别名]
def ad_creative_success(response, stream=None):
'''A success callback for the FB Batch endpoint used when syncing AdCreatives. Needs the stream
to resolve schema refs and transform the successful response object.'''
refs = load_shared_schema_refs()
schema = singer.resolve_schema_references(stream.catalog_entry.schema.to_dict(), refs)
rec = response.json()
record = Transformer(pre_hook=transform_date_hook).transform(rec, schema)
singer.write_record(stream.name, record, stream.stream_alias, utils.now())