-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCronJob.py
More file actions
43 lines (34 loc) · 1.25 KB
/
CronJob.py
File metadata and controls
43 lines (34 loc) · 1.25 KB
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
from apscheduler.schedulers.blocking import BlockingScheduler
from Todoist import TodoIstAPI
from Notion import NotionAPI
from Gcal import GCalAPI
import json
import os
from Main import run_sync
def create_notion_api():
notion_config = json.loads(os.environ['notion_config'])
notion = NotionAPI(os.environ['tz'], notion_config)
return notion
def create_todoist_api():
todoist = TodoIstAPI(os.environ['TODOIST_TOKEN'])
return todoist
def create_gcal_api():
gcal_config = json.loads(os.environ['gcal_config'])
gcal = GCalAPI(os.environ['tz'], gcal_config)
return gcal
if __name__ == '__main__':
notion = create_notion_api()
if os.environ['SYNC_TODOIST'] == "True" and os.environ['SYNC_GCAL'] == "True":
todoist = create_todoist_api()
gcal = create_gcal_api()
args = [notion, todoist, gcal]
elif os.environ['SYNC_TODOIST'] == "True":
todoist = create_todoist_api()
args = [notion, todoist, None]
elif os.environ['SYNC_GCAL'] == "True":
gcal = create_gcal_api()
args = [notion, None, gcal]
# Create an instance of scheduler and add function.
scheduler = BlockingScheduler()
scheduler.add_job(run_sync, 'interval', seconds=90, args=args)
scheduler.start()