diff options
author | Robin Obůrka <r.oburka@gmail.com> | 2016-03-06 01:09:51 +0100 |
---|---|---|
committer | Robin Obůrka <r.oburka@gmail.com> | 2016-03-06 01:38:30 +0100 |
commit | 2b41a6e05abc1e47a12b9efb803af7bd7f192622 (patch) | |
tree | ba809219e628ccc3e0f6a8036792b53c4dd7ba5e | |
parent | Dump data as JSON (diff) | |
download | todoist-2b41a6e05abc1e47a12b9efb803af7bd7f192622.tar.xz |
Provide new interface for --dump operation
-rwxr-xr-x | todoist | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -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 |