From b3d81c43cc65aacb790bf309e0ee477776f797b0 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Tue, 12 Jun 2018 11:36:24 +0200 Subject: [PATCH] Tweak timeline output --- tests/test_console.py | 3 ++- toot/output.py | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/test_console.py b/tests/test_console.py index eabc1bc..198349e 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -109,7 +109,8 @@ def test_timeline(mock_get, monkeypatch, capsys): out, err = capsys.readouterr() assert "The computer can't tell you the emotional story." in out - assert "Frank Zappa @fz" in out + assert "Frank Zappa" in out + assert "@fz" in out @mock.patch('toot.http.post') diff --git a/toot/output.py b/toot/output.py index f019de1..6d17fab 100644 --- a/toot/output.py +++ b/toot/output.py @@ -124,16 +124,18 @@ def print_timeline(items): return chain(*[wrapper.wrap(l) for l in text.split("\n")]) def timeline_rows(item): - name = item['name'] + display_name = item['account']['display_name'] + username = "@" + item['account']['username'] time = item['time'].strftime('%Y-%m-%d %H:%M%Z') - left_column = [name, time] - if 'reblogged' in item: - left_column.append(item['reblogged']) + left_column = [display_name] + if display_name != username: + left_column.append(username) + left_column.append(time) + if item['reblogged']: + left_column.append("Reblogged @{}".format(item['reblogged'])) - text = item['text'] - - right_column = wrap_text(text, 80) + right_column = wrap_text(item['text'], 80) return zip_longest(left_column, right_column, fillvalue="") @@ -142,15 +144,14 @@ def print_timeline(items): def _parse_item(item): content = item['reblog']['content'] if item['reblog'] else item['content'] - reblogged = item['reblog']['account']['username'] if item['reblog'] else "" + reblogged = item['reblog']['account']['username'] if item['reblog'] else None - name = item['account']['display_name'] + " @" + item['account']['username'] soup = BeautifulSoup(content, "html.parser") text = soup.get_text().replace(''', "'") time = datetime.strptime(item['created_at'], "%Y-%m-%dT%H:%M:%S.%fZ") return { - "name": name, + "account": item['account'], "text": text, "time": time, "reblogged": reblogged,