umbenannt: modules/googlecal.py -> modules/off/googlecal.py

umbenannt:      modules/ig.py -> modules/off/ig.py
umbenannt:      modules/metar.py -> modules/off/metar.py
umbenannt:      modules/notam.py -> modules/off/notam.py
umbenannt:      modules/taf.py -> modules/off/taf.py
umbenannt:      modules/teamup.py -> modules/off/teamup.py
umbenannt:      modules/twitter.py -> modules/off/twitter.py
umbenannt:      modules/url.py -> modules/off/url.py
neue Datei:     modules/ping.py (check web urls)
This commit is contained in:
plocki 2020-02-01 22:48:35 +01:00
parent 166aa957b9
commit 78901ea505
9 changed files with 40 additions and 0 deletions

40
modules/ping.py Executable file
View File

@ -0,0 +1,40 @@
from timeit import default_timer as timer
import os
import sys
import urllib.request
from urllib.request import urlopen
class MatrixModule:
async def matrix_message(self, bot, room, event):
args = event.body.split()
args.pop(0)
url=args[0]
# check url
if (not (url.startswith('http://') or url.startswith('https://'))):
# print ("adding trailing https")
url="https://"+url
print(url)
start = timer()
try:
data = urlopen(url)
length = format(len(data.read())/1024,'.3g') #kB
retcode = data.getcode()
except Exception as e:
await bot.send_text(room, "Ping failed: " +str(e))
print ("Error: " + str(e))
return False
end = timer()
await bot.send_text(room, url + ": OK (" + str(retcode) + ") / " + "Size: "+ str(length) +
" kB / Time: " + str(format(end - start, '.3g')) +" sec")
def help(self):
return('check if IP or URL is accessable')