#! /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
