Watson icon indicating copy to clipboard operation
Watson copied to clipboard

ledger / hledger timeclock/timedot format

Open ieugen opened this issue 5 years ago • 5 comments

Hello,

I just found out about this app and I was wondering if there is some interest in adding support for outputing data in a format suitable for ledger and/or hledger.

Both ledger / hledger are accounting software that also track per project time (accounting tracking that is) . I think the match is made in heaven :). I think the projects should collaborate.

If Watson can export those formats, reporting could be delegated to those projects. Either partially or entirely.

There might be some marketing opportunity to add Watson to https://plaintextaccounting.org/ . Time tracking is basically accounting but for time.

The issue here is to serve as future reference as well.

https://hledger.org/timeclock.html https://hledger.org/timedot.html

https://github.com/plaintextaccounting/plaintextaccounting.github.io

Regards, Eugen

ieugen avatar Mar 30 '20 12:03 ieugen

Hi! Thank you for your suggestion.

For this kind of integrations, we prefer to encourage third parties. We try not to add too many external dependencies to Watson in order to reduce the maintenance burden.

As Watson is able to output JSON, it should be rather straightforward to write an integration with this format, and publish it as an independent script. We're always happy to share those integrations in the readme & the doc.

k4nar avatar Mar 30 '20 13:03 k4nar

I'm using both, Watson and Ledger CLI. Watson to Ledger is literally 80 LOC (Python). I'm using watson --csv to feed the script that will then output in Ledger format.

loonies avatar Apr 07 '20 15:04 loonies

Do you have an open repository for this script @loonies?

jmaupetit avatar Apr 07 '20 16:04 jmaupetit

Not really, I've just put up something quick that works for me. Here is an exerpt, but YMMV:

#!/usr/bin/env python

# pylint: disable=invalid-name

import csv
import subprocess
from datetime import datetime
from datetime import timedelta
from io import StringIO

ARGS = [
    'watson', 'log',
    '--project', '<project>',
    '--from', '<from>',
    '--to', '<to>',
    '--csv',
]
DELIMITER = ','
QUOTECHAR = '"'
DATETIME_FORMAT_WATSON = '%Y-%m-%d %H:%M:%S'
DATETIME_FORMAT_LEDGER = '%Y-%m-%d'

def main():
    content = subprocess.run(ARGS, stdout=subprocess.PIPE)
    content = StringIO(content.stdout.decode('utf-8'))

    data = {}
    for row in csv.DictReader(content, delimiter=DELIMITER, quotechar=QUOTECHAR):
        start = datetime.strptime(row['start'], DATETIME_FORMAT_WATSON)
        stop = datetime.strptime(row['stop'], DATETIME_FORMAT_WATSON)

        tags = row['tags'].split(',')
        tags = map(str.strip, tags)

        time = stop - start

        description = '...'

        # ...

    for _, taskframe in data.items():
        print(...)
        print(...)

if __name__ == '__main__':
    main()

loonies avatar Apr 07 '20 17:04 loonies

It would be nice if this is up-streamed and available for distribution so it's easy to consume.

ieugen avatar Apr 08 '20 07:04 ieugen