dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 6c84ff749c174b99d4e970cbfd57edbb65fee2f1
parent 87a20b4d0e1460dc2c79ec1ac65c5696f8b84a84
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Sun, 21 Apr 2024 19:51:58 +0200

Switch from ourhome to flatastic

Unfortunately ourhome seems to be gone.

Diffstat:
Memacs/config.org | 19++++++++++---------
Ascripts/flatastic.rb | 36++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/emacs/config.org b/emacs/config.org @@ -1990,7 +1990,8 @@ Skip ones with a habit tag: (let ((skip (save-excursion (org-end-of-subtree t))) (keep nil) (item-tags-without-inherited (let ((org-use-tag-inheritance nil)) (org-get-tags)))) - (if (member "HABIT" item-tags-without-inherited) + (if (or (member "HABIT" item-tags-without-inherited) + (member "flatastic" item-tags-without-inherited)) skip keep))) #+end_src @@ -2555,8 +2556,8 @@ And a function to rsync to my VPS: API work is handled via an external ruby script. #+begin_src emacs-lisp - (defun za/org-ourhome-sync-tasks () - "Add tasks from OurHome to inbox" + (defun za/org-flatastic-sync-tasks () + "Add tasks from flatastic to inbox" (interactive) (unless (json-available-p) (user-error "JSON not available")) @@ -2566,19 +2567,19 @@ API work is handled via an external ruby script. (progn (require 'exec-path-from-shell) (exec-path-from-shell-copy-envs - '("OURHOME_CLIENT_ID" "OURHOME_USER" "OURHOME_PASS")) - (shell-command-to-string "~/.local/share/rbenv/shims/ruby ~/.scripts/ourhome.rb")) + '("FLATASTIC_API_KEY" "FLATASTIC_USER_ID")) + (shell-command-to-string "~/.local/share/rbenv/shims/ruby ~/.scripts/flatastic.rb")) :object-type 'alist)) (format-data-as-org (lambda (l) - (format "* TODO %s :ourhome:\n SCHEDULED: <%s>\n Points: %d\n" + (format "* TODO %s :flatastic:\n SCHEDULED: <%s>\n Points: %d\n" (alist-get 'description l) (alist-get 'scheduled_due_date l) (alist-get 'point_value l)))) - (org-ourhome-items (mapcar format-data-as-org api-data))) + (org-flatastic-items (mapcar format-data-as-org api-data))) (with-current-buffer (find-file-noselect za/org-life-inbox) (goto-char (point-max)) - (insert "\n" (string-join org-ourhome-items "\n"))) - (message "Synced %d OurHome tasks to inbox" (length api-data)))) + (insert "\n" (string-join org-flatastic-items "\n"))) + (message "Synced %d Flatastic tasks to inbox" (length api-data)))) #+end_src *** org-caldav diff --git a/scripts/flatastic.rb b/scripts/flatastic.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +require 'uri' +require 'net/http' +require 'json' +require 'time' + +%w[FLATASTIC_API_KEY FLATASTIC_USER_ID].each do |env_var| + abort "#{env_var} not set in environment" unless ENV.key? env_var +end + +my_user_id = ENV['FLATASTIC_USER_ID'].to_i +api_key = ENV['FLATASTIC_API_KEY'] + +headers = { + 'accept' => 'application/json, text/plain, */*', + 'origin' => 'https://app.flatastic-app.com', + 'referer' => 'https://app.flatastic-app.com/', + 'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', + 'x-api-key' => api_key, + 'x-api-version' => '2.0.0', + 'x-client-version' => '2.3.35' +} + +base_url = URI 'https://api.flatastic-app.com' +https = Net::HTTP.new(base_url.host, base_url.port) +https.use_ssl = true + +url = "#{base_url}/index.php/api/chores" +resp = JSON.parse(https.get(url, headers).body) +my_tasks = resp + .select { _1['currentUser'] == my_user_id } + .map { {'description' => _1['title'], + 'scheduled_due_date' => Time.at(Time.now.to_i + _1['timeLeftNext']), # close enough + 'point_value' => _1['points']} } + +print my_tasks.to_json