-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (38 loc) · 1.64 KB
/
main.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
52
53
54
55
import notion_scripts
from integrations import wakatime, rescue_time, todoist
from apscheduler.schedulers.blocking import BlockingScheduler
import threading
import os
def todoist_sync():
already_saved_tasks = notion_scripts.not_todoist.get_db_added_tasks_id()
tasks = todoist.get_tasks_history(already_saved_tasks)
notion_scripts.not_todoist.save_tasks(tasks)
def rescue_time_sync():
stats = rescue_time.get_daily_data()
notion_scripts.not_rescuetime.save_rescuetime_data(stats)
def wakatime_sync():
stats = wakatime.get_dates_summaries()
notion_scripts.not_wakatime.save_wakatime_data(stats)
def goals_sync():
goals_todoist_tasks = todoist.get_completed_goals_tasks()
notion_scripts.not_goals.save_goals_tasks(goals_todoist_tasks)
def sync_apps():
threads = [
threading.Thread(target=todoist_sync),
threading.Thread(target=rescue_time_sync),
threading.Thread(target=wakatime_sync),
threading.Thread(target=goals_sync)
]
[t.start() for t in threads]
[t.join() for t in threads]
def schedule_synchronizer():
scheduler = BlockingScheduler(timezone=os.getenv('SYNC_TIMEZONE'))
scheduler.add_job(sync_apps, 'interval', hours=int(os.getenv('SYNC_EVERY_HOURS')), )
day_reviews_time = os.getenv('SYNC_DAY_REVIEWS_AT').split(':')
scheduler.add_job(notion_scripts.day_reviews.create_day_review_page, 'cron', id='day_reviews', hour=int(day_reviews_time[0]),
minute=int(day_reviews_time[1]))
scheduler.start()
if __name__ == '__main__':
sync_apps()
schedule_synchronizer()
# notion_scripts.day_reviews.create_day_review_page()