aboutsummaryrefslogtreecommitdiffstats
path: root/todoist
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2016-03-06 01:09:51 +0100
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2016-03-06 01:38:30 +0100
commit2b41a6e05abc1e47a12b9efb803af7bd7f192622 (patch)
treeba809219e628ccc3e0f6a8036792b53c4dd7ba5e /todoist
parentDump data as JSON (diff)
downloadtodoist-2b41a6e05abc1e47a12b9efb803af7bd7f192622.tar.xz
Provide new interface for --dump operation
Diffstat (limited to 'todoist')
-rwxr-xr-xtodoist15
1 files changed, 8 insertions, 7 deletions
diff --git a/todoist b/todoist
index d028a2e..e2ab94f 100755
--- a/todoist
+++ b/todoist
@@ -25,7 +25,6 @@ import json
import todoist
TOKEN_FILE_NAME = ".todoist_token"
-DUMP_FILENAME = "dump.txt"
def arg_parser():
parser = argparse.ArgumentParser()
@@ -37,8 +36,9 @@ def arg_parser():
help="Get current token (e.g. for revocation)",
action="store_true")
parser.add_argument("--dump",
- help="Dump data to file to " + DUMP_FILENAME + " and exit",
- action="store_true")
+ metavar="FILE",
+ help="Dump data to FILE (use - for stdout) and exit",
+ type=argparse.FileType("w"))
parser.add_argument("-p", "--project",
metavar="PROJECT_NAME",
help="Project name (lowercase!)",
@@ -88,9 +88,10 @@ def store_token(token):
with open(path, mode="w+") as f:
f.write(token)
-def dump(data):
- with open(DUMP_FILENAME, mode="w") as f:
- f.write(json.dumps(data, ensure_ascii=False, indent=4))
+def dump(to, data):
+ to.write(json.dumps(data, ensure_ascii=False, indent=4))
+ to.write("\n")
+ to.flush()
def build_project_list(data):
projects = { proj["name"].lower(): proj["id"] for proj in data["Projects"] }
@@ -150,7 +151,7 @@ def main():
sys.exit(1)
if args.dump:
- dump(data)
+ dump(args.dump, data)
sys.exit(0)
## Prepare data structures