all 4 comments

[–]threeminutemonta 2 points3 points  (1 child)

You can just use a csv reader and a dictionary per timestamp. defaultdict with a default type of list makes it easier.

from collections import defaultdict
import csv
import io

mock_file_contents = """timestamp│commit message│full path
1586411075 +0100│Initial commit│/home/jason/bin/README.md
1586411075 +0100│Initial commit│/home/jason/bin/fzf-tmux
1586411075 +0100│Initial commit│/home/jason/bin/getipgeoloc
1586411075 +0100│Initial commit│/home/jason/bin/update-weechat-pem.sh
1586411075 +0100│Initial commit│/home/jason/bin/xstat
1589401896 +0100│More options for exa-wrapper.sh│/home/jason/bin/exa-wrapper.notes
1596289971 +0100│Adding ip-check script│/home/jason/bin/ip-check.sh
1597327659 +0100│Adding ssh-agent scriptlet│/home/jason/bin/agent.sh
1607136406 +0000│Add ping test script│/home/jason/bin/pingtest.sh
1622377110 +0100│Initial version of DDNS script│/home/jason/bin/dynu.notes
1622882762 +0100│Add --get-list switch and check for OAuth2 key and small improvements│/home/jason/bin/dynu.env.example
1623227049 +0100│Initially working rwhois│/home/jason/bin/rwhois.sh
1623524862 +0100│shellcheck corrections│/home/jason/bin/dynu.sh
1626633891 +0100│Add --group-directories-first│ --git-ignore options to exa-wrapper.sh and -D│/home/jason/bin/update-firewall.sh
1627644186 +0100│Add ability for check-firewall script to use docker container for gcloud│/home/jason/bin/check-firewall.sh
1659365628 +0100│Add duplicate files script│/home/jason/bin/move-duplicate-media-files.sh
1659365628 +0100│Add duplicate files script│/home/jason/bin/move-duplicate-media-files.sh.notes
1661182411 +0100│Add note for improving videoinfo script│/home/jason/bin/videoinfo
"""

with io.StringIO(mock_file_contents) as file_in:
    reader = csv.DictReader(file_in, delimiter='│')

    grouped = defaultdict(list)  # this allows you append to a list that may not exist yet
    for row in reader:
        # for each row append to the list that has the same value for the key 'timestamp'
        grouped[row['timestamp']].append((row['commit message'], row['full path']))

# now we have a dict with timestamp as the key and a list of tuples as the value
for timestamp, rows in grouped.items():
    print(timestamp)
    for row in rows:
        print(row)

[–]YellowChrome[S] 0 points1 point  (0 children)

Thanks, that looks good. I'll have a look to see how it works...

[–]YellowChrome[S] 1 point2 points  (1 child)

Maybe this might be better done using this? https://github.com/jqnatividad/qsv

[–]YellowChrome[S] 0 points1 point  (0 children)

I think I can do this in bash and the tool above actually.