-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
149 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include LICENSE | ||
include tap_pardot/schemas/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"username": "my_username", | ||
"password": "my_password", | ||
"start_date": "2017-01-01T00:00:00Z" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python | ||
from setuptools import setup | ||
|
||
setup( | ||
name="tap-pardot", | ||
version="0.1.0", | ||
description="Singer.io tap for extracting data", | ||
author="Stitch", | ||
url="http://singer.io", | ||
classifiers=["Programming Language :: Python :: 3 :: Only"], | ||
py_modules=["tap_pardot"], | ||
install_requires=[ | ||
"singer-python>=5.0.12", | ||
"requests", | ||
], | ||
entry_points=""" | ||
[console_scripts] | ||
tap-pardot=tap_pardot:main | ||
""", | ||
packages=["tap_pardot"], | ||
package_data = { | ||
"schemas": ["tap_pardot/schemas/*.json"] | ||
}, | ||
include_package_data=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import json | ||
import singer | ||
from singer import utils, metadata | ||
|
||
REQUIRED_CONFIG_KEYS = ["start_date", "username", "password"] | ||
LOGGER = singer.get_logger() | ||
|
||
def get_abs_path(path): | ||
return os.path.join(os.path.dirname(os.path.realpath(__file__)), path) | ||
|
||
# Load schemas from schemas folder | ||
def load_schemas(): | ||
schemas = {} | ||
|
||
for filename in os.listdir(get_abs_path('schemas')): | ||
path = get_abs_path('schemas') + '/' + filename | ||
file_raw = filename.replace('.json', '') | ||
with open(path) as file: | ||
schemas[file_raw] = json.load(file) | ||
|
||
return schemas | ||
|
||
def discover(): | ||
raw_schemas = load_schemas() | ||
streams = [] | ||
|
||
for schema_name, schema in raw_schemas.items(): | ||
|
||
# TODO: populate any metadata and stream's key properties here.. | ||
stream_metadata = [] | ||
stream_key_properties = [] | ||
|
||
# create and add catalog entry | ||
catalog_entry = { | ||
'stream': schema_name, | ||
'tap_stream_id': schema_name, | ||
'schema': schema, | ||
'metadata' : [], | ||
'key_properties': [] | ||
} | ||
streams.append(catalog_entry) | ||
|
||
return {'streams': streams} | ||
|
||
def get_selected_streams(catalog): | ||
''' | ||
Gets selected streams. Checks schema's 'selected' first (legacy) | ||
and then checks metadata (current), looking for an empty breadcrumb | ||
and mdata with a 'selected' entry | ||
''' | ||
selected_streams = [] | ||
for stream in catalog.streams: | ||
stream_metadata = metadata.to_map(stream.metadata) | ||
# stream metadata will have an empty breadcrumb | ||
if metadata.get(stream_metadata, (), "selected"): | ||
selected_streams.append(stream.tap_stream_id) | ||
|
||
return selected_streams | ||
|
||
def sync(config, state, catalog): | ||
|
||
selected_stream_ids = get_selected_streams(catalog) | ||
|
||
# Loop over streams in catalog | ||
for stream in catalog.streams: | ||
stream_id = stream.tap_stream_id | ||
stream_schema = stream.schema | ||
if stream_id in selected_stream_ids: | ||
# TODO: sync code for stream goes here... | ||
LOGGER.info('Syncing stream:' + stream_id) | ||
return | ||
|
||
@utils.handle_top_exception(LOGGER) | ||
def main(): | ||
|
||
# Parse command line arguments | ||
args = utils.parse_args(REQUIRED_CONFIG_KEYS) | ||
|
||
# If discover flag was passed, run discovery mode and dump output to stdout | ||
if args.discover: | ||
catalog = discover() | ||
print(json.dumps(catalog, indent=2)) | ||
# Otherwise run in sync mode | ||
else: | ||
if args.catalog: | ||
catalog = args.catalog | ||
else: | ||
catalog = discover() | ||
|
||
sync(args.config, args.state, catalog) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"type": ["null", "object"], | ||
"additionalProperties": false, | ||
"properties": { | ||
"string_field": { | ||
"type": ["null", "string"] | ||
}, | ||
"datetime_field": { | ||
"type": ["null", "string"], | ||
"format": "date-time" | ||
}, | ||
"integer_field": { | ||
"type": ["null", "integer"] | ||
}, | ||
"double_field": { | ||
"type": ["null", "number"] | ||
} | ||
} | ||
} |