Last active
April 21, 2021 12:54
-
-
Save stask/67ff1d4328f546960f1962a56b63075f to your computer and use it in GitHub Desktop.
A simple babashka script to get a list of tasks from Todoist in a format that is easy to use in Roam Research.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(ns stask.todoist | |
(:require | |
[clojure.tools.cli :as tools.cli] | |
[org.httpkit.client :as client] | |
[cheshire.core :as json] | |
[clojure.string :as string])) | |
(def cl-options | |
[["-t" "--token TOKEN" "Todoist API token"] | |
["-h" "--help" "Help"]]) | |
(defn unfuck-title [content] | |
;; in some cases, the `content` is already a Markdown link | |
;; if that's that case, we want to extract the title of the link | |
(if-let [[_ title _] (re-find #"^\[([^\]]+)\]\(.+\)$" content)] | |
title | |
content)) | |
(defn list-tasks [token [filter]] | |
(->> {:query-params {"filter" filter} | |
:headers {"Authorization" (format "Bearer %s" token)}} | |
(client/get "https://api.todoist.com/rest/v1/tasks") | |
deref | |
:body | |
json/parse-string | |
(map (fn [{:strs [url content]}] | |
(format "[%s](%s)" (unfuck-title content) url))) | |
(string/join \newline) | |
println)) | |
(defn run-command [[command & arguments] {:keys [token]}] | |
(case command | |
"list" (list-tasks token arguments) | |
(println (format "Unsupported command [%s] [%s]" command arguments)))) | |
;; main | |
(defn main [{:keys [options summary errors arguments]}] | |
(let [has-option? (partial contains? options)] | |
(cond | |
(seq errors) (println summary) | |
(has-option? :help) (println summary) | |
(has-option? :token) (run-command arguments options) | |
:else (println summary)))) | |
(main (tools.cli/parse-opts *command-line-args* cl-options)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get your personal API token for todoist, save the script somewhere in your PATH, make sure it's executable, and use it like that:
And then paste it in your daily note in Roam. It will paste markdown links to the tasks, with title and link back to Todoist task.
It's not a real integration of course, but it allows to have tasks in Todoist and notes in Roam.
You will need to have babashka installed.