<filename>chatbot/py_commands/speedtest.py
import subprocess

import chatbot.utils.emojis

from .command import Command


class Speedtest(Command):
    def __init__(self, telegram_object, conf_obj):
        super().__init__(telegram_object, conf_obj)

        self.command_name = "speedtest"

    def run(self, args_list):

        # send status msg
        chat_id = self.telegram_object.chat_id
        self.telegram_object.send_msg(
            "{} Running speedtest...please wait {}".format(
                chatbot.utils.emojis.graph(), chatbot.utils.emojis.hour_glass()
            ),
            chat_id,
        )

        # perform speedtest
        speedtest_info = []
        speedtest_cmd = "speedtest | egrep -w \"Testing from|Download|Upload\" | sed -r 's/Testing from.*?\(/My IP: /g; s/\)\.\.\.//g; s/Download/D/g; s/Upload/U/g; s/bit\/s/bps/g'"

        try:
            speedtest_output = (
                subprocess.check_output(speedtest_cmd, shell=True).decode().strip()
            )
            speedtest_info = speedtest_output.split("\n")
        except subprocess.CalledProcessError as exc:
            output = exc.output.decode()
            error = ["Err: Speedtest error", output]
            print(error)
            return False

        if len(speedtest_info) == 0:
            speedtest_info.append("No output sorry")

        return self._render(speedtest_info)

    def help(self):
        """
        Return the help page for this command
        """
        short_msg = "speedtest: Run an Ookla speedtest from probe."
        long_msg = """speedtest: This command runs a speedtest to the Ookla speedtest service from the probe.

It provides the upload and download speed from the probe to the Internet. 

(This test requires your probe to have Internet access)"""

        if self.display_mode == "compact":
            return short_msg
        else:
            return chatbot.utils.emojis.help() + " " + long_msg

<filename>chatbot/py_commands/speedtest.py
import subprocess

import chatbot.utils.emojis

from .command import Command


class Speedtest(Command):
    def __init__(self, telegram_object, conf_obj):
        super().__init__(telegram_object, conf_obj)

        self.command_name = "speedtest"

    def run(self, args_list):

        # send status msg
        chat_id = self.telegram_object.chat_id
        self.telegram_object.send_msg(
            "{} Running speedtest...please wait {}".format(
                chatbot.utils.emojis.graph(), chatbot.utils.emojis.hour_glass()
            ),
            chat_id,
        )

        # perform speedtest
        speedtest_info = []
        speedtest_cmd = "speedtest | egrep -w \"Testing from|Download|Upload\" | sed -r 's/Testing from.*?\(/My IP: /g; s/\)\.\.\.//g; s/Download/D/g; s/Upload/U/g; s/bit\/s/bps/g'"

        try:
            speedtest_output = (
                subprocess.check_output(speedtest_cmd, shell=True).decode().strip()
            )
            speedtest_info = speedtest_output.split("\n")
        except subprocess.CalledProcessError as exc:
            output = exc.output.decode()
            error = ["Err: Speedtest error", output]
            print(error)
            return False

        if len(speedtest_info) == 0:
            speedtest_info.append("No output sorry")

        return self._render(speedtest_info)

    def help(self):
        """
        Return the help page for this command
        """
        short_msg = "speedtest: Run an Ookla speedtest from probe."
        long_msg = """speedtest: This command runs a speedtest to the Ookla speedtest service from the probe.

It provides the upload and download speed from the probe to the Internet. 

(This test requires your probe to have Internet access)"""

        if self.display_mode == "compact":
            return short_msg
        else:
            return chatbot.utils.emojis.help() + " " + long_msg

# send status msg # perform speedtest Return the help page for this command speedtest: This command runs a speedtest to the Ookla speedtest service from the probe.  It provides the upload and download speed from the probe to the Internet.   (This test requires your probe to have Internet access)