code-dumps/aws/aws-health-events-tg.sh

54 lines
1.3 KiB
Bash

#!/usr/bin/python3
import feedparser
import sqlite3
import smtplib
import json
import requests
feeds = ['https://status.aws.amazon.com/rss/ec2-ap-east-1.rss',
'https://status.aws.amazon.com/rss/rds-ap-east-1.rss',
'https://status.aws.amazon.com/rss/vpnvpc-ap-east-1.rss',
'https://status.aws.amazon.com/rss/directconnect-ap-east-1.rss',
'https://status.aws.amazon.com/rss/directconnect-ap-southeast-1.rss']
dbconn = sqlite3.connect('aws-rss.db')
for f in feeds:
NewsFeed = feedparser.parse(f)
for e in NewsFeed.entries:
try:
dbconn.execute("insert into rss values (?,?,?,?,false)", (e.id, e.published, e.title, e.summary))
except sqlite3.IntegrityError:
pass
dbconn.commit()
results = dbconn.execute('select * from rss where notified = false')
msg = " "
records = results.fetchall()
if len(records) == 0:
print("All events already notified")
quit()
url = 'https://api.telegram.org/botXXX/sendMessage'
for r in records:
lineBreak = "\n"
content = lineBreak.join((
r[0].split('#')[1].split('-')[0].upper() + " // <b>" + r[2] + "</b>",
"PublishTime: " + r[1],
"<pre>",
r[3],
"</pre>"))
tgMessage = {
"chat_id": 1111111,
"parse_mode": "HTML",
"text": content
}
requests.post(url, json=tgMessage)
dbconn.execute('update rss set notified = true where notified = false')
dbconn.commit()
dbconn.close()