-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscheduler.py
More file actions
37 lines (29 loc) · 1.09 KB
/
Copy pathscheduler.py
File metadata and controls
37 lines (29 loc) · 1.09 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
# scheduler.py
import threading
from apscheduler.schedulers.blocking import BlockingScheduler
import telegram_notifier
def run_flask():
"""Start the Flask server."""
from flask_app import app
app.run(port=5000)
def schedule_task():
"""Schedule the task."""
flask_thread = threading.Thread(target=run_flask)
flask_thread.start()
try:
import almaweb_client
from os import getenv
client = almaweb_client.AlmaWebClient(getenv('ALMAWEB_USERNAME'), getenv('ALMAWEB_PASSWORD'))
formatted_schedule = client.get_schedule()
if formatted_schedule:
notifier = telegram_notifier.TelegramNotifier(getenv('TELEGRAM_BOT_TOKEN'), getenv('TELEGRAM_CHAT_ID'))
notifier.notify(formatted_schedule)
else:
print("Failed to retrieve schedule")
except Exception as e:
print(f"Error in scheduling task: {e}")
def start_scheduler():
"""Start the scheduler."""
scheduler = BlockingScheduler()
scheduler.add_job(schedule_task, 'cron', day_of_week='sun', hour=12, minute=0, second=0)
scheduler.start()