Skip to content

Commit

Permalink
Merge pull request #19 from rseabrook/config_destination_path
Browse files Browse the repository at this point in the history
Add configurable destination_path
  • Loading branch information
KAllan357 authored Jan 14, 2019
2 parents 07d2d7b + 2033651 commit 1b73164
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config.sample.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"delimiter": "\t",
"quotechar": "'"
"quotechar": "'",
"destination_path": ""
}
6 changes: 4 additions & 2 deletions target_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def flatten(d, parent_key='', sep='__'):
items.append((new_key, str(v) if type(v) is list else v))
return dict(items)

def persist_messages(delimiter, quotechar, messages):
def persist_messages(delimiter, quotechar, messages, destination_path):
state = None
schemas = {}
key_properties = {}
Expand All @@ -59,6 +59,7 @@ def persist_messages(delimiter, quotechar, messages):
validators[o['stream']].validate(o['record'])

filename = o['stream'] + '-' + now + '.csv'
filename = os.path.expanduser(os.path.join(destination_path, filename))
file_is_empty = (not os.path.isfile(filename)) or os.stat(filename).st_size == 0

flattened_record = flatten(o['record'])
Expand Down Expand Up @@ -139,7 +140,8 @@ def main():
input_messages = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
state = persist_messages(config.get('delimiter', ','),
config.get('quotechar', '"'),
input_messages)
input_messages,
config.get('destination_path', ''))

emit_state(state)
logger.debug("Exiting normally")
Expand Down

0 comments on commit 1b73164

Please sign in to comment.