Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert daily files to a yearly file #386

Open
baogiadoan opened this issue Apr 6, 2022 · 5 comments
Open

Convert daily files to a yearly file #386

baogiadoan opened this issue Apr 6, 2022 · 5 comments

Comments

@baogiadoan
Copy link

baogiadoan commented Apr 6, 2022

Is your feature request related to a problem? Please describe.

The problem is that I used Org-journal for a long time and my setting for org-journal is 'daily which means that I have a lot of separate files now; however, my need changes and I used 'yearly as the moment; however, I can't see how I still keep the old journals (i.e. convert them into a yearly files)

Describe the solution you'd like

A function to convert the daily files into a single yearly file compatible with the current `yearly that I set up

@bastibe
Copy link
Owner

bastibe commented Apr 7, 2022

I'm afraid there's currently no such functionality implemented in org-journal.

But if anyone wants to contribute a function or external script, I'll happily accept a pull request.

@chasecaleb
Copy link

Hi, I just converted daily files to monthly like this:

;;; -*- lexical-binding: t -*-
(require 'org)
(require 'org-refile)
(require 'org-journal)
(require 'cl-lib)

;; Step 1: convert
(org-map-entries
 (lambda ()
   (let* ((original (file-name-base (buffer-file-name)))
          (year (substring original 0 4))
          (month (substring original 4 6))
          (day (substring original 6 8))
          (new-ts (format-time-string org-journal-created-property-timestamp-format
                                      (encode-time (org-parse-time-string (format "%s-%s-%s" year month day)))))
          (dest (expand-file-name (concat year month ".org")
                                  (file-name-directory (buffer-file-name))))
          (org-refile-keep t))
     (cl-labels ((post-refile ()
                              (org-set-property "CREATED" new-ts)
                              (save-buffer)))
       (let ((org-after-refile-insert-hook (list #'post-refile)))
         (org-refile nil nil `("fake-toplevel-heading" ,dest nil nil))))))
 "LEVEL=1"
 (directory-files org-journal-dir t (rx bos (= 8 digit) ".org" eos)))

;; Step 2: delete original dailies after reviewing results.
(seq-do #'delete-file
        (directory-files org-journal-dir t (rx bos (= 8 digit) ".org" eos)))

This isn't quite polished enough to merge as is, but it's really close if anyone wants to finish it up. I think these are the only assumptions that need to be fixed:

  1. Assumes daily files are named like yyyymmdd.org (see directory-files regexp arg).
  2. Assumes monthly files should be named yyyymm.org (see dest variable). Should use org-journal-file-format to create the destination file name instead.

@bastibe
Copy link
Owner

bastibe commented Jun 21, 2022

Wonderful, thank you! Would you like to add it to the README as a code example of how to do this sort of thing?

@chasecaleb
Copy link

I don't have time to put together a pull request, sorry... my comment was just a quick drive-by for posterity. You're welcome to put it in the readme or use it however you'd like though.

@baogiadoan
Copy link
Author

baogiadoan commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants