alarm script
This commit is contained in:
parent
d473749fb2
commit
b60eb29035
40
telegram.py
Normal file
40
telegram.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import re
|
||||||
|
import telebot, sys
|
||||||
|
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||||
|
#import logging
|
||||||
|
|
||||||
|
SHOW_BTN = False
|
||||||
|
|
||||||
|
#logger = telebot.logger
|
||||||
|
#telebot.logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
BOT_TOKEN=''
|
||||||
|
DESTINATION=sys.argv[1]
|
||||||
|
SUBJECT=sys.argv[2]
|
||||||
|
MESSAGE=sys.argv[3]
|
||||||
|
|
||||||
|
def extractIPs(fileContent):
|
||||||
|
pattern = r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)([ (\[]?(\.|dot)[ )\]]?(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})"
|
||||||
|
ips = [each[0] for each in re.findall(pattern, fileContent)]
|
||||||
|
for item in ips:
|
||||||
|
location = ips.index(item)
|
||||||
|
ip = re.sub("[ ()\[\]]", "", item)
|
||||||
|
ip = re.sub("dot", ".", ip)
|
||||||
|
ips.remove(item)
|
||||||
|
ips.insert(location, ip)
|
||||||
|
return ips[0]
|
||||||
|
|
||||||
|
#chat -1001397537526
|
||||||
|
#MESSAGE = MESSAGE.replace('/n','\n')
|
||||||
|
tb = telebot.TeleBot(BOT_TOKEN)
|
||||||
|
if SHOW_BTN:
|
||||||
|
IP = extractIPs(MESSAGE)
|
||||||
|
keyboard = InlineKeyboardMarkup()
|
||||||
|
url_btn = InlineKeyboardButton(text="Open", url=str(IP))
|
||||||
|
keyboard.add(url_btn)
|
||||||
|
|
||||||
|
tb.send_message(DESTINATION ,SUBJECT + '\n' + MESSAGE, reply_markup = keyboard)
|
||||||
|
else:
|
||||||
|
tb.send_message(DESTINATION ,SUBJECT + '\n' + MESSAGE)
|
Loading…
Reference in New Issue
Block a user