Skip to content

filename attribute added #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions target_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def flatten(d, parent_key='', sep='__'):
return dict(items)


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

filename = o['stream'] + '-' + now + '.csv'
filename = filename + '.csv' if filename else 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

Expand Down Expand Up @@ -107,7 +107,7 @@ def persist_messages(delimiter, quotechar, messages, destination_path, fixed_hea
key_properties[stream] = o['key_properties']
else:
logger.warning("Unknown message type {} in message {}"
.format(o['type'], o))
.format(o['type'], o))

return state

Expand Down Expand Up @@ -151,6 +151,7 @@ def main():
input_messages = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
state = persist_messages(config.get('delimiter', ','),
config.get('quotechar', '"'),
config.get('filename', ''),
input_messages,
config.get('destination_path', ''),
config.get('fixed_headers'),
Expand Down