simonw / csv-diff

Python CLI tool and library for diffing CSV and JSON files
Apache License 2.0
292 stars 47 forks source link

Feature for adding extra templated output to the diff #38

Closed simonw closed 3 weeks ago

simonw commented 3 weeks ago

For this project: https://github.com/simonw/scrape-hacker-news-by-domain

I want to include latest links in the human readable output that link to https://news.ycombinator.com/latest?id=41459472 for each item.

I'm going to try using Python format strings like this:

csv-diff --format json simon-previous.json simon.json --key id --extra latest 'https://news.ycombinator.com/latest?id={id}'
simonw commented 3 weeks ago

Got that working:

3 rows changed

  id: 41459472
    points: "24" => "25"
    numComments: "5" => "6"
  extras:
    latest: https://news.ycombinator.com/latest?id=41459472

  id: 41434857
    points: "1" => "2"
  extras:
    latest: https://news.ycombinator.com/latest?id=41434857

  id: 41427834
    points: "2" => "3"
  extras:
    latest: https://news.ycombinator.com/latest?id=41427834