From 2b41a6e05abc1e47a12b9efb803af7bd7f192622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Ob=C5=AFrka?= Date: Sun, 6 Mar 2016 01:09:51 +0100 Subject: Provide new interface for --dump operation --- todoist | 15 ++++++++------- 1 file 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 -- cgit v1.2.3