Skip to content

Commit

Permalink
flatten subcommand
Browse files Browse the repository at this point in the history
This adjusts the subcommand to work with ensure_flattened.
  • Loading branch information
edsu committed May 31, 2021
1 parent c715bc0 commit 45d7616
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions twarc/command2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 45d7616

Please sign in to comment.