-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
28 lines (21 loc) · 708 Bytes
/
Copy pathapp.py
File metadata and controls
28 lines (21 loc) · 708 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
26
27
from flask import Flask
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"))
app = Flask(__name__)
@app.route('/')
def homepage():
now = int(time.time())
previous_connection = r.get('connection_time')
r.set('connection_time', now)
if not previous_connection:
return ""
if not r.get('is_connected'):
telegram.send_message(os.environ.get("TELEGRAM_USER_ID"), "Connected after {} seconds".format(now - int(previous_connection)))
r.set('is_connected', 'connected')
return ""
if __name__ == '__main__':
app.run(debug=True, use_reloader=True)