add a module to grab speedtest results
Diff
dave/dave.py | 7 ++++---
dave/module.py | 9 +++++++++
dave/modules/speedtest.py | 23 +++++++++++++++++++++++
dave/modules/title.py | 2 --
dave/modules/urbandictionary.py | 1 -
5 files changed, 36 insertions(+), 6 deletions(-)
@@ -77,9 +77,10 @@
method[1](self, method[2], nick, channel)
for m in run:
m[0](self, m[1], nick, channel)
if not (hasattr(method[1], "dont_always_run") and method[1].dont_always_run):
for m in run:
m[0](self, m[1], nick, channel)
def irc_unknown(self, prefix, command, params):
if command == "INVITE":
@@ -75,6 +75,15 @@
return add_attribute
def dont_always_run_if_run():
"""If this function is run, we shouldn't run the functions that should always run"""
def add_attribute(function):
function.dont_always_run = True
return function
return add_attribute
def always_run():
"""Decorate a function to always run it, even when over prioritied"""
def add_attribute(function):
@@ -1,0 +1,23 @@
from requests import get
from bs4 import BeautifulSoup
import dave.module
from twisted.words.protocols.irc import assembleFormattedText, attributes as A
@dave.module.match(r'https?://(?:www\.|beta\.)?speedtest\.net/(?:my-)?result/([0-9]+)')
@dave.module.priority(dave.module.Priority.HIGHEST)
@dave.module.dont_always_run_if_run()
def speedtest(bot, args, sender, source):
res = get("http://www.speedtest.net/result/{}".format(args[0]), timeout=3)
soup = BeautifulSoup(res.text, "html.parser")
download = soup.select(".share-speed.share-download p")[0].text
upload = soup.select(".share-speed.share-upload p")[0].text
ping = soup.select(".share-data.share-ping p")[0].text
isp = soup.select(".share-data.share-isp p")[0].text
bot.msg(source, assembleFormattedText(A.normal[
A.bold["{}: ".format(isp)],
"Download: ", A.bold[str(download)], " ",
"Upload: ", A.bold[str(upload)], " ",
"Ping: ", A.bold[str(ping)]
]))
@@ -6,10 +6,8 @@
from requests import get
from twisted.words.protocols.irc import assembleFormattedText, attributes as A
import dave.config
import socket
parse = re.compile(r"(?:(?:https?):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?", re.IGNORECASE)
@dave.module.match(r"(.*)")
@dave.module.always_run()
@@ -1,8 +1,7 @@
"""Give the user back urbandictionary results."""
import dave.module
import dave.config
import socket
import requests
import pickle
import re