Compare commits
78 Commits
23ef7f13ee
...
7a20f3fdda
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a20f3fdda | ||
|
|
7618d5665b | ||
|
|
a5869aaa89 | ||
|
|
b1df4b62af | ||
|
|
87c937b6f1 | ||
|
|
ed474b8c3a | ||
|
|
46e62dc485 | ||
|
|
236355b69d | ||
|
|
6bb6c847aa | ||
|
|
6bad1e1365 | ||
|
|
d105df15e9 | ||
|
|
afc7d6001a | ||
|
|
242f9ee1b4 | ||
|
|
5a30481ff1 | ||
|
|
438c0ade59 | ||
|
|
e5b3fd3195 | ||
|
|
49893c7ffe | ||
|
|
39d222b133 | ||
|
|
461e88ee17 | ||
|
|
916ad212f4 | ||
|
|
bd5028ff8d | ||
|
|
21ccb7ff4c | ||
|
|
1b1ed01937 | ||
|
|
5a1936721d | ||
|
|
77fb27dc09 | ||
|
|
2eda765ad9 | ||
|
|
a8fbc13e7c | ||
|
|
d8e732087a | ||
|
|
7d98e6f0fc | ||
|
|
82a615919c | ||
|
|
50913b8913 | ||
|
|
42d532ee61 | ||
|
|
24316fe690 | ||
|
|
8058304219 | ||
|
|
7f24b3f337 | ||
|
|
fc12e0550d | ||
|
|
05f5244cd1 | ||
|
|
c559c8eba6 | ||
|
|
dd7ac8d786 | ||
|
|
ccdd2615c4 | ||
|
|
0241f2d76c | ||
|
|
fa812a16ee | ||
|
|
cf3b233a11 | ||
|
|
64868bdc0b | ||
|
|
1b1724bea7 | ||
|
|
f4968d1d1b | ||
|
|
6203ced79b | ||
|
|
4d171d10d0 | ||
|
|
8ad2ca9345 | ||
|
|
bc0bb05fb6 | ||
|
|
22dc04341c | ||
|
|
bf10c00708 | ||
|
|
cd5ce0f0df | ||
|
|
eb41f065a5 | ||
|
|
96bfb96ee3 | ||
|
|
770f2719d2 | ||
|
|
3554bf8ba4 | ||
|
|
b4aa4ad310 | ||
|
|
0dddf26265 | ||
|
|
5afdeed3b5 | ||
|
|
af0f094a65 | ||
|
|
031db8788b | ||
|
|
b8efdbfa52 | ||
|
|
a54ccae4c2 | ||
|
|
a27d5c38d7 | ||
|
|
cb4886992a | ||
|
|
15c5f03ccf | ||
|
|
b82f11c248 | ||
|
|
3c9b34202b | ||
|
|
967a02c90a | ||
|
|
3ed7d8cd9e | ||
|
|
492e0af993 | ||
|
|
10b95672e3 | ||
|
|
183f39bd2a | ||
|
|
24154df995 | ||
|
|
f7dac79233 | ||
|
|
8c45d4a7df | ||
|
|
1e3f24b4d5 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,4 +4,3 @@ cmd/cmd
|
|||||||
cmd/cli
|
cmd/cli
|
||||||
cmd/pttodo/pttodo
|
cmd/pttodo/pttodo
|
||||||
cmd/pttodo-cli/pttodo-cli
|
cmd/pttodo-cli/pttodo-cli
|
||||||
cmd/pttodo-cli
|
|
||||||
|
|||||||
40
cmd/add.go
40
cmd/add.go
@@ -1,40 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func add(config *config) error {
|
|
||||||
if config.add == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
v := pttodo.Todo{
|
|
||||||
Todo: config.add,
|
|
||||||
Schedule: pttodo.Schedule(config.addSchedule),
|
|
||||||
Tags: config.addTags,
|
|
||||||
}
|
|
||||||
newTarget, err := _add(config.targets, v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
config.targets = append(config.targets, newTarget)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func _add(filepaths []string, todo pttodo.Todo) (string, error) {
|
|
||||||
target := filepaths[0] + ".todo." + uuid.New().String()
|
|
||||||
|
|
||||||
c, err := yaml.Marshal([]pttodo.Todo{todo})
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return target, nil
|
|
||||||
}
|
|
||||||
46
cmd/pttodo-cli/add.go
Normal file
46
cmd/pttodo-cli/add.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func add(config config) error {
|
||||||
|
if config.add == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
v := pttodo.Todo{
|
||||||
|
Todo: config.add,
|
||||||
|
Schedule: pttodo.Schedule(config.addSchedule),
|
||||||
|
Tags: config.addTags,
|
||||||
|
}
|
||||||
|
return _add(config.targets, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _add(filepaths []string, todo pttodo.Todo) error {
|
||||||
|
target := filepaths[0]
|
||||||
|
var original pttodo.Root
|
||||||
|
|
||||||
|
r, err := filePathReader(target)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := yaml.NewDecoder(r).Decode(&original); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
original.Todo = append([]pttodo.Todo{todo}, original.Todo...)
|
||||||
|
original.AutoMove()
|
||||||
|
|
||||||
|
c, err := yaml.Marshal(original)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := ioutil.WriteFile(target, c, os.ModePerm); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -12,4 +12,4 @@ require (
|
|||||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace gogs.inhome.blapointe.com/bel/pttodo => ./..
|
replace gogs.inhome.blapointe.com/bel/pttodo => ../..
|
||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -29,7 +30,7 @@ func main() {
|
|||||||
|
|
||||||
func _main() error {
|
func _main() error {
|
||||||
config := getConfig()
|
config := getConfig()
|
||||||
if err := add(&config); err != nil {
|
if err := add(config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := edit(config); err != nil {
|
if err := edit(config); err != nil {
|
||||||
@@ -38,6 +39,31 @@ func _main() error {
|
|||||||
return dump(config)
|
return dump(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func verifyRoot(root pttodo.Root) error {
|
||||||
|
f, err := ioutil.TempFile(os.TempDir(), "tmp")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
tempFile := f.Name()
|
||||||
|
b, err := yaml.Marshal(root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(tempFile, b, os.ModePerm); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.Remove(tempFile)
|
||||||
|
return verifyFile(tempFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func verifyFile(path string) error {
|
||||||
|
if err := _dump(io.Discard, []string{path}, nil, "", DUMP_ALL); err != nil {
|
||||||
|
return fmt.Errorf("failed verifying file %s: %w", path, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func merge(filepath string, mergeTargetFilePath string) error {
|
func merge(filepath string, mergeTargetFilePath string) error {
|
||||||
baseReader, err := filePathReader(filepath)
|
baseReader, err := filePathReader(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -67,6 +93,9 @@ func merge(filepath string, mergeTargetFilePath string) error {
|
|||||||
|
|
||||||
base.MergeIn(merging)
|
base.MergeIn(merging)
|
||||||
|
|
||||||
|
if err := verifyRoot(base); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
tmppath, err := marshalRootToTempFile(base)
|
tmppath, err := marshalRootToTempFile(base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
21
cmd/xfer/all_from_todo_server_to_pttodo.sh
Normal file
21
cmd/xfer/all_from_todo_server_to_pttodo.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
main() {
|
||||||
|
cd "$(dirname "$BASH_SOURCE")"
|
||||||
|
source ./from_todo_server_to_pttodo.sh
|
||||||
|
type from_todo_server_to_pttodo_main
|
||||||
|
list_lists | jq .list[] | jq -c . | while read -r line; do
|
||||||
|
local name="$(echo "$line" | jq -r .name | sed 's/^Today$/todo/g' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')"
|
||||||
|
local id="$(echo "$line" | jq -r .id)"
|
||||||
|
echo $name, $id
|
||||||
|
TODO_SERVER_LIST="$id" from_todo_server_to_pttodo_main > ./$name.yaml
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
list_lists() {
|
||||||
|
todo_server_curl "$TODO_SERVER_URL/ajax.php?loadLists=&rnd=0.9900282499544026"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$0" == "$BASH_SOURCE" ]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
55
cmd/xfer/from_todo_server_to_pttodo.sh
Normal file
55
cmd/xfer/from_todo_server_to_pttodo.sh
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
export TODO_SERVER_URL="${TODO_SERVER_URL:-"https://todo-server.remote.blapointe.com"}"
|
||||||
|
export TODO_SERVER_HEADERS="${TODO_SERVER_HEADERS:-"Cookie: BOAuthZ=$TODO_SERVER_BOAUTHZ"}"
|
||||||
|
export TODO_SERVER_LIST="${TODO_SERVER_LIST:-"2548023766"}"
|
||||||
|
|
||||||
|
main() {
|
||||||
|
from_todo_server_to_pttodo_main "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
from_todo_server_to_pttodo_main() {
|
||||||
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
local tasks_in_todo="$(fetch_tasks_in_list | format_tasks_in_list)"
|
||||||
|
local schedule_tasks_in_flight="$(COMPL=1 LOOPING=1 fetch_tasks_in_list | format_tasks_in_list)"
|
||||||
|
echo "{\"todo\": $tasks_in_todo, \"scheduled\": $schedule_tasks_in_flight, \"done\": []}" | yq -P eval -
|
||||||
|
}
|
||||||
|
|
||||||
|
format_tasks_in_list() {
|
||||||
|
jq -c .list[] | while read -r line; do
|
||||||
|
echo "$line" \
|
||||||
|
| jq '{
|
||||||
|
todo: .title,
|
||||||
|
details:.note,
|
||||||
|
ts: (if .compl == 1 then (.dateCompleted | strptime("%d %b %Y %I:%M %p") | mktime) else .dateEditedInt end),
|
||||||
|
subtasks: [],
|
||||||
|
tags: .tags,
|
||||||
|
schedule: (if (.cron != "") then (.cron) else (.loop) end)
|
||||||
|
}' \
|
||||||
|
| jq -c .
|
||||||
|
done | jq -sc | yq -P eval - | grep -v -E ' (""|\[]|0s)$' | yq -j eval - | jq -c .
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch_tasks_in_list() {
|
||||||
|
todo_server_curl "$TODO_SERVER_URL/ajax.php?loadTasks=&list=$TODO_SERVER_LIST&compl=${COMPL:-0}&looping=${LOOPING:-0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
todo_server_curl() {
|
||||||
|
local csv_headers="$TODO_SERVER_HEADERS"
|
||||||
|
local headers=()
|
||||||
|
while [ "$csv_headers" != "" ]; do
|
||||||
|
header="${csv_headers%%,*}"
|
||||||
|
headers+=("-H" "${header%%:*}: ${header#*:}")
|
||||||
|
if echo "$csv_headers" | grep -q ,; then
|
||||||
|
csv_headers="${csv_headers#*,}"
|
||||||
|
else
|
||||||
|
csv_headers=""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
curl -sS "${headers[@]}" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$0" == "$BASH_SOURCE" ]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
@@ -1,36 +1,11 @@
|
|||||||
package pttodo
|
package pttodo
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Root struct {
|
type Root struct {
|
||||||
Todo []Todo
|
Todo []Todo
|
||||||
Scheduled []Todo
|
Scheduled []Todo
|
||||||
Done []Todo
|
Done []Todo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRootFromFile(p string) (Root, error) {
|
|
||||||
f, err := os.Open(p)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return Root{}, nil
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return Root{}, err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
var result Root
|
|
||||||
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
|
|
||||||
return Root{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result.AutoMove()
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (root Root) Equals(other Root) bool {
|
func (root Root) Equals(other Root) bool {
|
||||||
for i, slice := range [][2][]Todo{
|
for i, slice := range [][2][]Todo{
|
||||||
[2][]Todo{root.Todo, other.Todo},
|
[2][]Todo{root.Todo, other.Todo},
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Todo struct {
|
type Todo struct {
|
||||||
@@ -20,24 +17,6 @@ type Todo struct {
|
|||||||
writeTS bool
|
writeTS bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTodosFromFile(p string) ([]Todo, error) {
|
|
||||||
f, err := os.Open(p)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
var result []Todo
|
|
||||||
if err := yaml.NewDecoder(f).Decode(&result); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (todo Todo) ID() string {
|
func (todo Todo) ID() string {
|
||||||
hash := crc32.NewIEEE()
|
hash := crc32.NewIEEE()
|
||||||
fmt.Fprintf(hash, "%d:%s", 0, todo.Todo)
|
fmt.Fprintf(hash, "%d:%s", 0, todo.Todo)
|
||||||
|
|||||||
Reference in New Issue
Block a user