-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.py
More file actions
25 lines (20 loc) · 685 Bytes
/
Copy pathclock.py
File metadata and controls
25 lines (20 loc) · 685 Bytes
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
from apscheduler.schedulers.blocking import BlockingScheduler
import time
import os
import redis
from telegram import Bot
r = redis.from_url(os.environ.get("REDIS_URL"))
telegram = Bot(os.environ.get("TELEGRAM_BOT_TOKEN"))
sched = BlockingScheduler()
@sched.scheduled_job('interval', minutes=3)
def timed_job():
now = time.time()
last_connection = r.get('connection_time')
if not last_connection:
return
last_connection = int(last_connection)
if now - last_connection > 120:
if r.get('is_connected'):
r.set('is_connected', '')
telegram.send_message(os.environ.get("TELEGRAM_USER_ID"), 'No connection')
sched.start()