This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
77 lines (56 loc) · 2.23 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import asyncio
from modules import sync_gdrive, renamer, fix_border, unmatched_assets
from utility.logger import setup_logger
from utility.config import Config
from datetime import datetime, timedelta
config = Config(script_name="global")
logger = setup_logger(config.log_level, "spp")
async def step_one():
logger.debug("Step 1: ------------ Running ------------")
sync_gdrive.main()
logger.debug("Step 1: ------------ Finished ------------")
async def step_two():
logger.debug("Step 2: ------------ Running ------------")
renamer.main()
logger.debug("Step 2: ------------ Finished ------------")
async def step_three():
logger.debug("Step 3: ------------ Running ------------")
fix_border.main()
logger.debug("Step 3: ------------ Finished ------------")
async def step_four():
logger.debug("Step 4: ------------ Running ------------")
unmatched_assets.main()
logger.debug("Step 4: ------------ Finished ------------")
# Run tasks immediately if run_now is True
async def run_tasks(run_now):
logger.debug(f"run_now: {run_now}")
if run_now:
await step_one()
await step_two()
await step_three()
# await step_four()
# Create and run the asyncio event loop
async def main():
# Run tasks immediately (if run_now is True)
await run_tasks(config.run_now)
if int(config.schedule_hour == -1):
logger.debug("scheduling disabled. exit")
return
while True:
# Get the current time
now = datetime.now()
logger.debug(f"Current time: {now}")
# Calculate the next run time based on the specified hour
next_run = datetime(now.year, now.month, now.day, int(config.schedule_hour), 0)
# If the next run time has already passed for today, set it for the same time tomorrow
if now >= next_run:
next_run += timedelta(days=1)
# Calculate the number of seconds to wait until the next run
wait_seconds = (next_run - now).total_seconds()
logger.info(f"Sleep duration in seconds: {wait_seconds}")
await asyncio.sleep(wait_seconds)
# Run scheduled tasks
await run_tasks(True)
# Run the asyncio event loop
if __name__ == "__main__":
asyncio.run(main())