Compare commits
85 Commits
7a20f3fdda
...
23ef7f13ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23ef7f13ee | ||
|
|
02dab4b726 | ||
|
|
cdd1be46a8 | ||
|
|
760c822323 | ||
|
|
4e69646e88 | ||
|
|
9aee322c4e | ||
|
|
887875f6d8 | ||
|
|
d2f986d8b6 | ||
|
|
58aa05c155 | ||
|
|
97aff0f0b8 | ||
|
|
eb20706d12 | ||
|
|
a800227c6f | ||
|
|
2c7563c1ab | ||
|
|
a8a135bb2f | ||
|
|
c1c625afc0 | ||
|
|
0b790e3468 | ||
|
|
7175d777cb | ||
|
|
debe28dbbc | ||
|
|
c1426566a0 | ||
|
|
6f79f7da5e | ||
|
|
284d7c06bd | ||
|
|
be702b1d74 | ||
|
|
de62d99340 | ||
|
|
bca9259caa | ||
|
|
dccf5c4028 | ||
|
|
55e174e3b1 | ||
|
|
d7dab75f48 | ||
|
|
3426deae4d | ||
|
|
7fe4686c05 | ||
|
|
eb57593665 | ||
|
|
814ae3ab23 | ||
|
|
939793bd3f | ||
|
|
1d26cf125f | ||
|
|
e20ce478d5 | ||
|
|
0bd6347a93 | ||
|
|
20770ff5e6 | ||
|
|
65178b8bdf | ||
|
|
4066d4aeb5 | ||
|
|
7f611e67bc | ||
|
|
71c03f3ef5 | ||
|
|
4b8d82c2a0 | ||
|
|
850ff92d98 | ||
|
|
c2d1381607 | ||
|
|
33ca7c60e1 | ||
|
|
cde6ea6cb6 | ||
|
|
6d3f423845 | ||
|
|
fe1bd22987 | ||
|
|
6f9589b100 | ||
|
|
a0c0cb7053 | ||
|
|
4a22b964db | ||
|
|
2caf2ae352 | ||
|
|
455a7d52d5 | ||
|
|
1a9221f7c7 | ||
|
|
6178e6ff93 | ||
|
|
fdb24fcc60 | ||
|
|
8002b5e75c | ||
|
|
3dd8cd1e03 | ||
|
|
c6ab36806d | ||
|
|
bf997c1814 | ||
|
|
69eb868db6 | ||
|
|
0c80162394 | ||
|
|
c634fdd4d4 | ||
|
|
92d76443bc | ||
|
|
a51d5e6960 | ||
|
|
7fc594d5c2 | ||
|
|
2d8cfa6397 | ||
|
|
f01dc04277 | ||
|
|
249ee84688 | ||
|
|
4111d1f490 | ||
|
|
5b6f62983b | ||
|
|
1056f5d29e | ||
|
|
7886723fe3 | ||
|
|
ff77af9ed4 | ||
|
|
3bd1c6462d | ||
|
|
3bcabde553 | ||
|
|
604cd610a1 | ||
|
|
9d35347b0c | ||
|
|
1a8c687260 | ||
|
|
3246900db0 | ||
|
|
79cc171af5 | ||
|
|
a75d898487 | ||
|
|
f63f152b0e | ||
|
|
76a0231511 | ||
|
|
7f37feea77 | ||
|
|
b84f8b59c9 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ 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
Normal file
40
cmd/add.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
@@ -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,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@@ -30,7 +29,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 {
|
||||||
@@ -39,31 +38,6 @@ 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 {
|
||||||
@@ -93,9 +67,6 @@ 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
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#! /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
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#! /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,11 +1,36 @@
|
|||||||
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,7 +4,10 @@ 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 {
|
||||||
@@ -17,6 +20,24 @@ 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