Skip to content

Commit

Permalink
automate replication key field selection (#5)
Browse files Browse the repository at this point in the history
* automate replication key field selection

* Upgrade singer-python

* version bump and CHANGELOG
  • Loading branch information
kethan1122 authored Mar 14, 2023
1 parent d9aad9f commit e06dbee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog

## 0.0.2
* Automates field selection for replication keys [#5](https://github.com/singer-io/tap-twilio/pull/5)

## 0.0.1
* Initial commit
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from setuptools import setup, find_packages

setup(name='tap-twilio',
version='0.0.1',
version='0.0.2',
description='Singer.io tap for extracting data from the Twilio API',
author='[email protected]',
classifiers=['Programming Language :: Python :: 3 :: Only'],
py_modules=['tap_twilio'],
install_requires=[
'backoff==1.8.0',
'requests==2.23.0',
'singer-python==5.9.0'
'singer-python==5.13.0'
],
entry_points='''
[console_scripts]
Expand Down
29 changes: 15 additions & 14 deletions tap_twilio/schema.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import os
import json
from singer import metadata
from singer.metadata import get_standard_metadata, to_list, to_map, write
from tap_twilio.streams import flatten_streams

# Reference:
# https://github.com/singer-io/getting-started/blob/master/docs/DISCOVERY_MODE.md#Metadata

def get_abs_path(path):
return os.path.join(os.path.dirname(os.path.realpath(__file__)), path)


def get_schemas():
schemas = {}
field_metadata = {}

flat_streams = flatten_streams()
for stream_name, stream_metadata in flat_streams.items():
schema_path = get_abs_path('schemas/{}.json'.format(stream_name))
with open(schema_path) as file:
with open(schema_path, encoding="utf-8") as file:
schema = json.load(file)
schemas[stream_name] = schema
mdata = metadata.new()

# Documentation:
# https://github.com/singer-io/getting-started/blob/master/docs/DISCOVERY_MODE.md#singer-python-helper-functions
# Reference:
# https://github.com/singer-io/singer-python/blob/master/singer/metadata.py#L25-L44
mdata = metadata.get_standard_metadata(
schema=schema,
key_properties=stream_metadata.get('key_properties', None),
valid_replication_keys=stream_metadata.get('replication_keys', None),
replication_method=stream_metadata.get('replication_method', None)
mdata = get_standard_metadata(
**{
"schema": schema,
"key_properties": stream_metadata.get('key_properties', None),
"valid_replication_keys": stream_metadata.get('replication_keys', None),
"replication_method": stream_metadata.get('replication_method', None),
}
)
mdata = to_map(mdata)
if stream_metadata.get('replication_keys') is not None:
for key in stream_metadata.get('replication_keys'):
mdata = write(mdata, ("properties", key), "inclusion", "automatic")
mdata = to_list(mdata)
field_metadata[stream_name] = mdata

return schemas, field_metadata

0 comments on commit e06dbee

Please sign in to comment.