certalert-bot/notifications_consumer.py

15 lines
457 B
Python
Raw Permalink Normal View History

2020-04-22 01:36:22 +02:00
import redis
import json
import os
2020-05-13 11:53:58 +02:00
import requests
2020-04-22 01:36:22 +02:00
r = redis.Redis()
2020-05-13 11:53:58 +02:00
token = os.environ.get('TOKEN')
print(token)
2020-04-22 01:36:22 +02:00
while True:
2020-05-13 11:53:58 +02:00
notification = json.loads(r.blpop('notifications')[1].decode('utf-8'))
2020-04-22 01:36:22 +02:00
print(notification)
2020-05-13 11:53:58 +02:00
res = requests.get("https://api.telegram.org/bot{}/sendMessage".format(token), params={"chat_id": notification["chat"], "text": "New cert for *{}*".format(notification["domain"]), "parse_mode": "Markdown"})
print(res.text)