-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (64 loc) · 3.45 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
78
79
import calendar
import time
from datetime import datetime
import schedule
import containerChecks
def generatePreviews(container, config):
cmdToRun = "occ preview:generate-all"
if not config.generateAll:
cmdToRun = "occ preview:pre-generate"
print(f"Now running the command `{cmdToRun}` in the nextcloud container for image preview generation!! This may take a while..")
container.exec_run(cmd=cmdToRun)
print(f"FINISHED: with the generating of the previews. See you at the next scheduled time. ;)")
def mainLastDayOfMonth():
# check to see if it is in fact the last day of the month - and if so, then allow the schedule to take place
today = datetime.today()
curDay = today.day
daysInCurMonth = calendar.monthrange(today.year, today.month)[1]
if (daysInCurMonth - 7) < curDay:
startMainProcess()
def handleScheduling(config):
if config.dailySchedule is not None:
schedule.every().day.at(config.dailySchedule.time).do(startMainProcess)
if config.weeklySchedule is not None:
if config.weeklySchedule.day == "MON":
schedule.every().monday.at(config.weeklySchedule.time).do(startMainProcess)
if config.weeklySchedule.day == "TUE":
schedule.every().tuesday.at(config.weeklySchedule.time).do(startMainProcess)
if config.weeklySchedule.day == "WED":
schedule.every().wednesday.at(config.weeklySchedule.time).do(startMainProcess)
if config.weeklySchedule.day == "THU":
schedule.every().thursday.at(config.weeklySchedule.time).do(startMainProcess)
if config.weeklySchedule.day == "FRI":
schedule.every().friday.at(config.weeklySchedule.time).do(startMainProcess)
if config.weeklySchedule.day == "SAT":
schedule.every().saturday.at(config.weeklySchedule.time).do(startMainProcess)
if config.weeklySchedule.day == "SUN":
schedule.every().sunday.at(config.weeklySchedule.time).do(startMainProcess)
if config.lastDayOfMonthSchedule is not None:
if config.lastDayOfMonthSchedule.day == "MON":
schedule.every().monday.at(config.lastDayOfMonthSchedule.time).do(mainLastDayOfMonth)
if config.lastDayOfMonthSchedule.day == "TUE":
schedule.every().tuesday.at(config.lastDayOfMonthSchedule.time).do(mainLastDayOfMonth)
if config.lastDayOfMonthSchedule.day == "WED":
schedule.every().wednesday.at(config.lastDayOfMonthSchedule.time).do(mainLastDayOfMonth)
if config.lastDayOfMonthSchedule.day == "THU":
schedule.every().thursday.at(config.lastDayOfMonthSchedule.time).do(mainLastDayOfMonth)
if config.lastDayOfMonthSchedule.day == "FRI":
schedule.every().friday.at(config.lastDayOfMonthSchedule.time).do(mainLastDayOfMonth)
if config.lastDayOfMonthSchedule.day == "SAT":
schedule.every().saturday.at(config.lastDayOfMonthSchedule.time).do(mainLastDayOfMonth)
if config.lastDayOfMonthSchedule.day == "SUN":
schedule.every().sunday.at(config.lastDayOfMonthSchedule.time).do(mainLastDayOfMonth)
def startMainProcess():
print("\n\nCOMMENCING THE SCHEDULED TASK TO GENERATE PREVIEWS..\n")
container, config = containerChecks.mainChecks()
generatePreviews(container, config)
def main():
print("STARTING SCRIPT!")
container, config = containerChecks.mainChecks()
handleScheduling(config)
while True:
schedule.run_pending()
time.sleep(1)
main()