Giter Club home page Giter Club logo

org-clock-csv's Introduction

Export Clock Entries from org-mode to CSV

org-clock-csv is an Emacs package that extracts clock entries from org files and convert them into CSV format. It is intended to facilitate clocked time analysis in external programs.

You can also read the original blog post.

Installation MELPA

org-clock-csv is available from MELPA. You can also install it manually by cloning the repository and adding the file to your load-path.

Usage in Interactive Mode

In interactive mode, calling org-clock-csv will open a buffer with the parsed entries from the files in org-agenda-files, while org-clock-csv-to-file will write this output to a file. Both functions take a prefix argument to read entries from the current buffer instead.

Both functions can also be called from lisp code to specify an explicit file list argument.

Usage in Batch Mode

Vanilla Emacs

There is an org-clock-csv-batch-and-exit command that is designed for use in batch mode (essentially, scripting Emacs), which will write CSV content to standard output (and then exit). Calling this function is similar to running tests with ert:

$ emacs -batch -l path/to/org-clock-csv.el \
    -f org-clock-csv-batch-and-exit \
    "~/org/todo.org" \
    > clock-entries.csv

The command accepts a file list as a series of command line arguments (there is only one in the example, but more can be given), or uses the content of org-agenda-files if there are none. You may also want to pipe the output to a file, as in the example.

Since Emacs is running in batch mode, it will not load your init.el file. This has two consequences: (1) any setq or customize code you have written for org or for this package will not be loaded; and (2) Emacs has not been told where your third-party packages are located. So this invokation will likely give you the following error:

Cannot open load file: No such file or directory, s

Since the third-party s library is needed to run org-clock-csv-batch. You can resolve this issue in a few ways. If you don't mind using the default settings of org and this package, the easiest is simply to let package.el (which you are probably using already) handle your third-party packages, as follows:

$ emacs -batch -l package --eval "(package-initialize)" \
    -l org-clock-csv -f org-clock-csv-batch-and-exit \
    "~/org/todo.org" \
    > clock-entries.csv

Alternatively, you can just load your entire init.el file, which will make all of your usual customizations to org and this package:

$ emacs -batch -l "~/.emacs.d/init.el" \
    -l org-clock-csv -f org-clock-csv-batch-and-exit \
    "~/org/todo.org" \
    > clock-entries.csv

(Beware that this method may write messages other than the CSV output to your file.)

Finally, you can simply write a little "shim" script, really a very slimmed-down version of your init.el file, that runs all of your setq code for org and this package and also sets up the load-path (using package.el or an equivalent) so that Emacs can find s and org-clock-csv, and call it as follows:

$ emacs -batch -l path/to/my-shim.el \
    -l org-clock-csv -f org-clock-csv-batch-and-exit \
    "~/org/todo.org" \
    > clock-entries.csv

Cask

If you are using Cask you can clone the repository and run cask install to install all the dependencies. To execute the org-clock-csv-batch-and-exit you can then simply run:

cask exec org-clock-csv <file> [files...]

Contributing

Contributions are welcome in the form of pull requests, although the scope of this package is intended to be small. If you have an org file that fails to parse as expected, feel free to open an issue.

All code is available under the GPLv3, the same license as Emacs itself. See the LICENSE file for details.

org-clock-csv's People

Contributors

atheriel avatar btljuice avatar dajva avatar fuco1 avatar gscano avatar milouse avatar smartintruesdell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

org-clock-csv's Issues

`duration` is not included in the default row format

Question

The default org-clock-csv-header list does not include duration by default and nor is it in the org-clock-csv-default-row-fmt.

I tried adding these and yes it prints out duration in the header list but adding (plist-get plist ':duration) to the org-clock-csv-default-row-fmt has no effect.

How can I add the duration value to the row output?

org-clock-csv--escape should be "public"

Since this can be called in a user-defined format function is should use the "public" convention, e.g. one less "-": org-clock-csv-escape.

If backwards compatibility is a concern you can do something like:

(defun org-clock-csv--escape (str)
  (warn "org-clock-csv--escape is deprecated and will be removed in version X. Use org-clock-csv-escape instead") 
  (org-clock-csv-escape str))

Using comma's in TODO items

When I use comma's in my todo lists then they are treated as extra columns;

Upgrade motherboard, CPU & RAM,,2012-11-29 13:05,2012-11-29 16:56,,,

Should the text be in quotes to fix this?

[SOLVED] org-journal and org-clock-csv

Hi, I'm using org-journal and I clock my activities on that file but it has no .org extension even though it is written as an org-mode buffer. Is it possible to overcome this limitation and run org-clock-csv on this buffer too?

Originally posted by @GCamp6 in #17 (comment)

Export from current file with prefix argument

Enhancement proposal

When called with an empty argument C-u M-x org-clock-csv, the functyion should parse just the visited buffer. This would act as a shortcut instead of writing out the full file name.

More descriptive usage documentation?

Thanks for making this package! Could you describe how to use this package a bit more? Targeted to non-emacs wizards (aka myself)? I understand how to do org-clock-csv via M-x. However, I want to run the org-clock-csv-batch command on a specific file via the terminal/command-line. What are the exact commands/process to use to do this?

Export clock notes

org supports per-clock notes when clocking out via:

#+STARTUP:   lognoteclock-out

Example:

CLOCK: [2018-02-12 Mon 12:35]--[2018-02-12 Mon 12:53] =>  0:18
- More notes
CLOCK: [2018-02-12 Mon 08:20]--[2018-02-12 Mon 11:31] =>  3:11
- Refactored stuff
  Ate a burrito
CLOCK: [2018-02-11 Sun 15:54]--[2018-02-11 Sun 17:33] =>  1:39
CLOCK: [2018-02-11 Sun 14:00]--[2018-02-11 Sun 14:43] =>  0:43

It would be nice if this could be exported to csv as well.

Provided Time as a List of Time Components

Currently a string is provided but this format may not be what those that define custom format functions want. Instead of having one parse the time string it's better to provide a list of (YYYY MM DD HH MM) and let them construct desired format.

Task column modification request

Would it be possible to include the header text from ancestors in the task column?

For an org file structured like this:

*Project 1
** Task1
    [clock data here]
** Task2
*Project 2
** Task1
** Task2

The current output is not so useful as the resulting CSV file doesn't contain any info to distinguish which project an individual clock event belongs to.

Rather than:

Task1,,,,,,
Task2,,,,,,
Task1,,,,,,
Task2,,,,,,

Maybe something like this:

Project1-Task1-SubTask1,,,,,,
Project1-Task2,,,,,,
Project2-Task1,,,,,,
Project2-Task2,,,,,,

Instead of Calling cl-assert, Signal Error With a Message

Just got an error message exporting to a file:

cl--assertion-failed: Assertion failed: (file-exists-p file)

Had to (setq debug-on-error t) to figure out why:

;; For the sake of better debug messages, check whether all of the
;; files exists first.
(mapc (lambda (file) (cl-assert (file-exists-p file))) filelist))

The irony of the associated comment is not lost on me 😄

Minimal required org-version

Hey,

This package seems to require an org-version higher than 8.2. Could this get included into the code?

With my initial setup this package stopped with the error that it cant find "(org-element-lineage current)". After upgrading to org-version 9.* from elpa using the package-manager it now works like a charm.

How do I gather entries from all org agenda files?

Hi,

Thanks for the great package. I'm currently using the following:

/Applications/Emacs.app/Contents/MacOS/Emacs \
    --batch -l package \
    --eval "(package-initialize)" \
    -l ./org-clock-csv.el -f org-clock-csv-batch-and-exit \
    ~/org/work.org \
    >work.csv

However, I'd like to gather & export entries from all agenda files, not just one (shown as ~/org/work.org above). Is there a way to do that? (My Emacs setup is Spacemacs by the way.)

Should Category inherit from #+CATEGORY ?

Most of my org docs contain a top-level #+CATEGORY declaration. The output after running org-clock-csv does not seem to pick this up (the Category column is always empty).

If I set a :CATEGORY: property on a single node it is included in the output. Would it be possible/useful for the output to use the inherited Category value?

This may also help with the issue raised in #3

File tags inheritance

I use the native org-mode feature #+FILETAGS. This has a hypothetical "level 0" for the Org headline hierarchy which all headlines inherit. See this page of the orgmode docs.

However, when I export my org files, no headlines inherit the file tags..

Is this something that is supported in org-clock-csv? I haven't been able to find it.

Thanks

Exporting the values of properties?

Context. In addition to tracking timelog data, I also track the :UTILITY: property for CLOSED tasks. So for example the following

* Open Task
      :PROPERTIES:
      :UTILITY:        0.75μ
      :END:
* COMPLETE Closed Task
      CLOSED: [2019-07-09 Tue 16:17]
      :PROPERTIES:
      :UTILITY:        0.5μ
      :END:
      :LOGBOOK:
      CLOCK: [2019-07-09 Tue 00:00]--[2019-07-09 Tue 00:20] =>  0:20
      :END:

shows 0.5μ of utility for CLOSED tasks.

Question: Is there a way to use org-clock-csv to export this sort of data? I suppose the important things to export are (i) whether a task is CLOSED (and if so what at what date); (ii) capturing the value of arbitrary properties (in this case :UTILITY:). I can use my own parsing logic to interpret the rest.

CSV content is not showing from my agenda

I just installed org-clock-csv and ran M-x org-clock-csv, it took me to a new buffer with the headings task,category,start,end,effort,ishabit,tags but never filled out the data.

I've got all my org files in my ~/org and ~/org/business directories and I add these like so;

;; Org-mode options
(add-hook 'org-mode-hook 'turn-on-visual-line-mode)
(setq org-clock-out-remove-zero-time-clocks t)
(setq org-directory "/org")
(setq org-agenda-files '("
/org/" "~/org/business"))

My full setup is at: https://github.com/map7/emacs-config
My setup is pretty big so it might be something to do with my setup which is not yet compatible with your plugin.

Let me know how I can supply more information to get it working.

Collect TITLE

The task and parents columns do no include any information about the file from which they originate. Because the filename or the TITLE can de facto be used as a structuring level on top of the headlines I think such information should be included in the output.

I am ready to send a PR, optionally adding the TITLE (or the filename in case there are no TITLE) as the first item in the parents column.
However, I would like to check with you if:

  1. there would be any general interest in this;
  2. the information should be reported in front of the parents column or if a new title column should be used.

In any case, I think that leaving the feature as optional and defaulting to not reporting this information would be the best option to not break any script using the csv output.

Thanks in advance.

ERT test 'test-issue-23' fails if 'STARTED' is not one of the TODO keywords

In my version of Emacs (v27.2) STARTED is not one of the default keywords, which causes the test-issue-23 test to fail for me. A possible solution is to specify per-file TODO keywords in the tests/issue-23.org file.

The following is the output from the ERT test. We can see that the STARTED keyword is being brought along from the parsed version of the tests/issue-23.org file which is causing the error.

F test-issue-23
    Test custom properties.
    (ert-test-failed
     ((should
       (equal in out))
      :form
      (equal "task,CUSTOM_1,CUSTOM_2,start,end
STARTED Example First Task,A Value,10,2021-01-01 08:00,2021-01-01 09:00
STARTED Example First Task,A Value,10,2021-01-01 06:00,2021-01-01 07:00
STARTED Example First Child Task,A Value,15,2021-01-04 06:00,2021-01-04 07:00
STARTED Example Second Task,defaultvalue,5,2021-01-01 09:00,2021-01-01 09:30
STARTED Example Second Child Task,defaultvalue,20,2021-01-04 07:00,2021-01-04 07:30
STARTED Example Third Task,defaultvalue,,2021-01-04 07:30,2021-01-04 08:00
" "task,CUSTOM_1,CUSTOM_2,start,end
Example First Task,A Value,10,2021-01-01 08:00,2021-01-01 09:00
Example First Task,A Value,10,2021-01-01 06:00,2021-01-01 07:00
Example First Child Task,A Value,15,2021-01-04 06:00,2021-01-04 07:00
Example Second Task,defaultvalue,5,2021-01-01 09:00,2021-01-01 09:30
Example Second Child Task,defaultvalue,20,2021-01-04 07:00,2021-01-04 07:30
Example Third Task,defaultvalue,,2021-01-04 07:30,2021-01-04 08:00
")
      :value nil :explanation
      (arrays-of-different-length 491 443 "task,CUSTOM_1,CUSTOM_2,start,end
STARTED Example First Task,A Value,10,2021-01-01 08:00,2021-01-01 09:00
STARTED Example First Task,A Value,10,2021-01-01 06:00,2021-01-01 07:00
STARTED Example First Child Task,A Value,15,2021-01-04 06:00,2021-01-04 07:00
STARTED Example Second Task,defaultvalue,5,2021-01-01 09:00,2021-01-01 09:30
STARTED Example Second Child Task,defaultvalue,20,2021-01-04 07:00,2021-01-04 07:30
STARTED Example Third Task,defaultvalue,,2021-01-04 07:30,2021-01-04 08:00
" "task,CUSTOM_1,CUSTOM_2,start,end
Example First Task,A Value,10,2021-01-01 08:00,2021-01-01 09:00
Example First Task,A Value,10,2021-01-01 06:00,2021-01-01 07:00
Example First Child Task,A Value,15,2021-01-04 06:00,2021-01-04 07:00
Example Second Task,defaultvalue,5,2021-01-01 09:00,2021-01-01 09:30
Example Second Child Task,defaultvalue,20,2021-01-04 07:00,2021-01-04 07:30
Example Third Task,defaultvalue,,2021-01-04 07:30,2021-01-04 08:00
" first-mismatch-at 33)))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.