From 45d7616e2d11a3c6205434a1567e93b4afd28263 Mon Sep 17 00:00:00 2001 From: Ed Summers Date: Mon, 31 May 2021 15:33:35 -0400 Subject: [PATCH] flatten subcommand This adjusts the subcommand to work with ensure_flattened. --- twarc/command2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/twarc/command2.py b/twarc/command2.py index 5cde54b3..56ef31d1 100644 --- a/twarc/command2.py +++ b/twarc/command2.py @@ -20,7 +20,7 @@ from twarc.version import version from twarc.handshake import handshake from twarc.decorators import cli_api_error -from twarc.expansions import flatten as flat +from twarc.expansions import ensure_flattened from click_config_file import configuration_option @@ -364,15 +364,16 @@ def conversation(T, tweet_id, archive, outfile): @cli_api_error def flatten(infile, outfile): """ - "Flatten" tweets, or move expansions inline with tweet objects. + "Flatten" tweets, or move expansions inline with tweet objects and ensure + that each line of output is a signle tweet. """ if (infile.name == outfile.name): click.echo(click.style(f"💔 Cannot flatten files in-place, specify a different output file!", fg='red'), err=True) return for line in infile: - result = json.loads(line) - _write(result, outfile, True) + for tweet in ensure_flattened(json.loads(line)): + _write(tweet, outfile, False) @twarc2.command('stream')