-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (40 loc) · 1.13 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
'''
Author: Dietrich Sinkevitch
Program: Tech Product Search Tool
Date: 08/08/2023
Github Link: https://github.com/dytryk/techproductsearchtool
'''
from website import create_app
import time
import schedule
import threading
import sys
from pathlib import Path
sys.path.insert(0, str(Path("website/notify.py").resolve().parent))
from website.notify import notify_all_users
app = create_app()
def job():
'''
The function calls 'notify_all_users' function from 'notify.py'
'''
notify_all_users()
print("emailed users")
# Clear any previously scheduled jobs
schedule.clear()
# Schedule the job to run at 4 AM every day
schedule.every().day.at("04:00").do(job)
schedule_lock = threading.Lock()
def run_schedule():
'''
This function runs the schedule to notify users.
'''
while True:
with schedule_lock:
schedule.run_pending()
# Check every minute
time.sleep(60)
# run the flask app
if __name__ == '__main__':
schedule_thread = threading.Thread(target=run_schedule)
schedule_thread.start()
app.run(debug=True)