This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
/
todoist_scheduler.py
executable file
·51 lines (48 loc) · 1.83 KB
/
todoist_scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
from task import Task
import pathlib
from template import execute_template
from api import API
import argparse
import pickle
import toml
parser = argparse.ArgumentParser(
description="""Todoist Scheduler can store future one-time or recurring tasks for Todoist \n
in plain text and create a task in Todoist when they are needed. \n
Also offers more features regarding a set of repeating tasks."""
)
parser.add_argument(
"-f", dest="forward", type=int, default=0, help="Execute tasks due in next X days."
)
parser.add_argument("-v", dest="verbose", action="store_true", help="Verbose output.")
parser.add_argument("--template", help="Run template file TEMPLATE")
args = parser.parse_args()
directory = pathlib.Path(__file__).resolve().parent
if __name__ == "__main__":
conf_file = directory / "todoist_scheduler.conf"
if not conf_file.is_file():
api = API.create_new(directory, missing_conf=True)
else:
conf = toml.load(str(conf_file))
token_location = conf.get("token")
if not token_location:
api = API.create_new(directory, missing_location=True)
else:
token = pickle.load(open(token_location, "rb"))
if not token:
api = API.create_new(directory, missing_token=True)
else:
api = API(token)
if api.valid:
if args.template:
execute_template(args.template, api)
else:
tasks = pathlib.Path(conf["tasks_directory"])
for filename in tasks.rglob("*.toml"):
if args.verbose:
print("Task: {}".format(filename.name))
task = Task.from_file(filename, api, args.verbose)
task.execute(args.forward)
else:
print("Token not valid")
exit(1)