summaryrefslogtreecommitdiffstats
path: root/emacsconf-upcoming.el
blob: 309d2d1b50cad29f5928b34c15f1485c49e7d1fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
;;; emacsconf-upcoming.el --- Update upcoming.org with information about the next talks  -*- lexical-binding: t; -*-

;; Copyright (C) 2021  Sacha Chua

;; Author: Sacha Chua <sacha@sachachua.com>
;; Keywords: data

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; 

;;; Code:

(defun emacsconf-upcoming-update-file ()
  (interactive)
  (with-current-buffer (find-file-noselect emacsconf-upcoming-file)
    (save-excursion
      (org-map-entries #'emacsconf-upcoming-insert-or-update "SLUG={.}")
)))

(defun emacsconf-upcoming-add-subtree ()
  (interactive)
  (org-map-entries #'emacsconf-upcoming-insert-or-update "SLUG={.}" 'tree)
  (save-excursion
    (with-current-buffer (find-file-noselect emacsconf-upcoming-file)
      (emacsconf-upcoming-sort))))

(defun emacsconf-upcoming-sort ()
  (interactive)
  ;; Sort
  (goto-char (point-min))
  (when (looking-at "\\*") (save-excursion (insert "\n"))) ;; Need to be before the first heading.
  (org-sort-entries
   nil ?f
   (lambda () (cons (org-entry-is-done-p) (org-entry-get (point) "SCHEDULED")))
   (lambda (a b)
     (cond
      ((and (car a) (car b)) (string< (cdr a) (cdr b)))
      ((car b) t)
      ((car a) nil)                   ; move done things to the bottom
      (t (string< (cdr a) (cdr b)))))))

(defun emacsconf-upcoming-insert-or-update-from-slug (slug)
  (interactive (list (emacsconf-complete-talk)))
  (save-excursion
    (emacsconf-with-talk-heading slug
      (emacsconf-upcoming-insert-or-update nil nil))))

(defun emacsconf-upcoming-insert-or-update (&optional info sort)
  (interactive (list nil nil))
  (let ((info
         (or info
             (when (buffer-file-name)
               (if (string= (expand-file-name (buffer-file-name)) emacsconf-org-file)
                   (emacsconf-get-talk-info-for-subtree)
                 (let ((slug (org-entry-get (point) "SLUG")))
                   (emacsconf-with-talk-heading slug
                     (emacsconf-get-talk-info-for-subtree)))))))
        pos)
    (when (and (plist-get info :slug) emacsconf-upcoming-file)
      (with-current-buffer (find-file-noselect emacsconf-upcoming-file)
        (setq pos (org-find-property "SLUG" (plist-get info :slug)))
        (if pos
            (goto-char pos)
          (goto-char (point-max))
          (unless (bolp) (insert "\n"))
          (insert (format "* TODO %s: %s - %s\n"
                          (plist-get info :slug)
                          (plist-get info :title)
                          (plist-get info :speakers))))
        (org-todo (plist-get info :status))
        (org-entry-put (point) "SLUG" (plist-get info :slug))
        (org-entry-put (point) "URL" (concat emacsconf-base-url emacsconf-year "/talks/" (plist-get info :slug)))
        (org-set-property "SCHEDULED" (plist-get info :scheduled))
        (unless (org-entry-get (point) "INTRO_NOTE")
          (org-entry-put (point) "INTRO_NOTE" (plist-get info :intro-note)))
        (when (or (plist-get info :pronouns) (plist-get info :pronunciation))
          (unless (org-entry-get (point) "OTHER_INFO")
            (org-entry-put (point) "OTHER_INFO"
                           (string-join (delq nil (list (plist-get info :pronouns) (plist-get info :pronunciation))) " "))))
        (org-entry-put (point) "PRESENT" (or (plist-get info :present) "?"))
        (org-entry-put (point) "DURATION"
                       (or (plist-get info :video-duration)
                           (concat "~ " (plist-get info :time))))
        (org-entry-put (point) "BUFFER"
                       (format "%s (ending ~ %s)"
                               (plist-get info :buffer)
                               (format-time-string
                                "%l:%M%p"
                                (seconds-to-time
                                 (+
                                  (time-to-seconds
                                   (org-timestamp-to-time (org-timestamp-split-range (org-timestamp-from-string (plist-get info :scheduled)))))
                                  (* 60 (string-to-number (plist-get info :time)))
                                  (* 60 (string-to-number (plist-get info :buffer)))))
                                emacsconf-timezone)))
        (org-entry-put (point) "Q_AND_A" 
                       (or (plist-get info :bbb-room)
                           (plist-get info :q-and-a)
                           "?"))
        ;(org-entry-put (point) "IRC"
        ;               (or (plist-get info :irc) "?"))
        (org-entry-put (point) "CHECK_IN"
                       (or (plist-get info :check-in) "?"))
        (org-entry-put (point) "EMAIL" (plist-get info :email))
        (if (plist-get info :contact)
            (org-entry-put (point) "CONTACT" (plist-get info :check-in)))
        (if sort (emacsconf-upcoming-sort))))))






(provide 'emacsconf-upcoming)
;;; emacsconf-upcoming.el ends here