当前位置: 首页>>代码示例>>Python>>正文


Python speedtest.Speedtest方法代码示例

本文整理汇总了Python中speedtest.Speedtest方法的典型用法代码示例。如果您正苦于以下问题:Python speedtest.Speedtest方法的具体用法?Python speedtest.Speedtest怎么用?Python speedtest.Speedtest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在speedtest的用法示例。


在下文中一共展示了speedtest.Speedtest方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: speedtest

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def speedtest(jarvis, s):
    """Runs a speedtest on your internet connection"""
    try:
        res = st.Speedtest()
    except st.ConfigRetrievalError:
        return jarvis.connection_error()

    # Create a spinner on command line to show that its running
    jarvis.spinner_start('Running the test ')

    res.get_best_server()
    download_speed = res.download()
    upload_speed = res.upload()

    jarvis.spinner_stop('')

    # Print the results
    jarvis.say('Speed test results:', Fore.GREEN)
    jarvis.say('Download: ' + pretty_speed(download_speed), Fore.GREEN)
    jarvis.say('Upload: ' + pretty_speed(upload_speed), Fore.GREEN) 
开发者ID:sukeesh,项目名称:Jarvis,代码行数:22,代码来源:speedtest.py

示例2: speedtestcmd

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def speedtestcmd(self, message):
        """Tests your internet speed"""
        await utils.answer(message, _("<code>Running speedtest...</code>"))
        args = utils.get_args(message)
        servers = []
        for server in args:
            try:
                servers += [int(server)]
            except ValueError:
                logger.warning("server failed")
        results = await utils.run_sync(self.speedtest, servers)
        ret = _("<b>Speedtest Results:</b>") + "\n\n"
        ret += _("<b>Download:</b> <code>{} MiB/s</code>").format(round(results["download"] / 2**20, 2)) + "\n"
        ret += _("<b>Upload:</b> <code>{} MiB/s</code>").format(round(results["upload"] / 2**20, 2)) + "\n"
        ret += _("<b>Ping:</b> <code>{} milliseconds</code>").format(round(results["ping"], 2)) + "\n"
        await utils.answer(message, ret) 
开发者ID:friendly-telegram,项目名称:modules-repo,代码行数:18,代码来源:speedtest.py

示例3: getresults

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def getresults():
    """Function to generate speedtest result."""
    spdtest = speedtest.Speedtest()
    spdtest.get_best_server()
    download = round(spdtest.download() / 1000 / 1000, 2)
    upload = round(spdtest.upload() / 1000 / 1000, 2)
    ping = round(spdtest.results.ping)

    return(download, upload, ping) 
开发者ID:frdmn,项目名称:google-speedtest-chart,代码行数:11,代码来源:speedtest-charts.py

示例4: speed_test

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def speed_test(_, message: Message):
    new_msg = await message.edit(
        "`Running speed test . . .`")
    spd = speedtest.Speedtest()

    new_msg = await message.edit(
        f"`{new_msg.text}`\n"
        "`Getting best server based on ping . . .`")
    spd.get_best_server()

    new_msg = await message.edit(
        f"`{new_msg.text}`\n"
        "`Testing download speed . . .`")
    spd.download()

    new_msg = await message.edit(
        f"`{new_msg.text}`\n"
        "`Testing upload speed . . .`")
    spd.upload()

    new_msg = await new_msg.edit(
        f"`{new_msg.text}`\n"
        "`Getting results and preparing formatting . . .`")
    results = spd.results.dict()

    await message.edit(
        WWW.SpeedTest.format(
            start=results['timestamp'],
            ping=results['ping'],
            download=SpeedConvert(results['download']),
            upload=SpeedConvert(results['upload']),
            isp=results['client']['isp']
        )) 
开发者ID:athphane,项目名称:userbot,代码行数:35,代码来源:www.py

示例5: speedtest

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def speedtest(event: NewMessage.Event) -> None:
    """
    Perform a speedtest with the best available server based on ping.


    `{prefix}speedtest` of **{prefix}speedtest (bits|bytes)**
    """
    unit = ("bit", 1)
    arg = event.matches[0].group(1)
    if arg and arg.lower() == "byte":
        unit = ("byte", 8)

    s = Speedtest()
    speed_event = await event.answer(testing % s.results.client)
    await _run_sync(s.get_servers)

    await _run_sync(s.get_best_server)
    text = (f"{speed_event.text}\n{hosted % s.results.server}")
    speed_event = await event.answer(text)

    await _run_sync(s.download)
    down, unit0, unit1 = await format_speed(s.results.download, unit)
    text = (f"{speed_event.text}\n{download % (down, unit0, unit1)}")
    speed_event = await event.answer(text)

    await _run_sync(s.upload)
    up, unit0, unit1 = await format_speed(s.results.upload, unit)
    text = (f"{speed_event.text}\n{upload % (up, unit0, unit1)}")
    extra = await get_chat_link(event, event.id)
    await event.answer(
        text,
        log=("speedtest", f"Performed a speedtest in {extra}.")
    ) 
开发者ID:TG-UserBot,项目名称:TG-UserBot,代码行数:35,代码来源:www.py

示例6: get_speed

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def get_speed():
    """
    Use Speedtest CLI to test bandwidth speed.
        :return: Download speed in Mbps
    """
    s = speedtest.Speedtest()
    s.download()
    results_dict = s.results.dict()
    return results_dict['download'] / 1048576  # convert bits to megabits 
开发者ID:healeycodes,项目名称:bandwidth-checker,代码行数:11,代码来源:clitest.py

示例7: __init__

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def __init__(self):
        self.name = _("Speedtest") 
开发者ID:friendly-telegram,项目名称:modules-repo,代码行数:4,代码来源:speedtest.py

示例8: speedtest

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def speedtest(self, servers):
        speedtester = speedtest.Speedtest()
        speedtester.get_servers(servers)
        speedtester.get_best_server()
        speedtester.download(threads=None)
        speedtester.upload(threads=None)
        return speedtester.results.dict() 
开发者ID:friendly-telegram,项目名称:modules-repo,代码行数:9,代码来源:speedtest.py

示例9: cmd_speedtest

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def cmd_speedtest(self, ctx: command.Context) -> str:
        before = util.time.usec()

        st = await util.run_sync(speedtest.Speedtest)
        status = "Selecting server..."

        await ctx.respond(status)
        server = await util.run_sync(st.get_best_server)
        status += f" {server['sponsor']} ({server['name']})\n"
        status += f"Ping: {server['latency']:.2f} ms\n"

        status += "Performing download test..."
        await ctx.respond(status)
        dl_bits = await util.run_sync(st.download)
        dl_mbit = dl_bits / 1000 / 1000
        status += f" {dl_mbit:.2f} Mbps\n"

        status += "Performing upload test..."
        await ctx.respond(status)
        ul_bits = await util.run_sync(st.upload)
        ul_mbit = ul_bits / 1000 / 1000
        status += f" {ul_mbit:.2f} Mbps\n"

        delta = util.time.usec() - before
        status += f"\nTime elapsed: {util.time.format_duration_us(delta)}"

        return status 
开发者ID:kdrag0n,项目名称:pyrobud,代码行数:29,代码来源:system.py

示例10: _

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def _(event):
    if event.fwd_from:
        return
    input_str = event.pattern_match.group(1)
    as_text = False
    as_document = True
    if input_str == "image":
        as_document = False
    elif input_str == "file":
        as_document = True
    elif input_str == "text":
        as_text = True
    await event.edit("Calculating my internet speed. Please wait!")
    start = datetime.now()
    s = speedtest.Speedtest()
    s.get_best_server()
    s.download()
    s.upload()
    end = datetime.now()
    ms = (end - start).microseconds / 1000
    response = s.results.dict()
    download_speed = response.get("download")
    upload_speed = response.get("upload")
    ping_time = response.get("ping")
    client_infos = response.get("client")
    i_s_p = client_infos.get("isp")
    i_s_p_rating = client_infos.get("isprating")
    reply_msg_id = event.message.id
    if event.reply_to_msg_id:
        reply_msg_id = event.reply_to_msg_id
    try:
        response = s.results.share()
        speedtest_image = response
        if as_text:
            await event.edit("""**SpeedTest** completed in {} seconds
Download: {}
Upload: {}
Ping: {}
Internet Service Provider: {}
ISP Rating: {}""".format(ms, convert_from_bytes(download_speed), convert_from_bytes(upload_speed), ping_time, i_s_p, i_s_p_rating))
        else:
            await borg.send_file(
                event.chat_id,
                speedtest_image,
                caption="**SpeedTest** completed in {} seconds".format(ms),
                force_document=as_document,
                reply_to=reply_msg_id,
                allow_cache=False
            )
            await event.delete()
    except Exception as exc:
        await event.edit("""**SpeedTest** completed in {} seconds
Download: {}
Upload: {}
Ping: {}

__With the Following ERRORs__
{}""".format(ms, convert_from_bytes(download_speed), convert_from_bytes(upload_speed), ping_time, str(exc))) 
开发者ID:mkaraniya,项目名称:BotHub,代码行数:60,代码来源:speedtest.py

示例11: _

# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def _(event):
    if event.fwd_from:
        return
    input_str = event.pattern_match.group(1)
    as_text = True
    as_document = False
    if input_str == "image":
        as_document = False
    elif input_str == "file":
        as_document = True
    elif input_str == "text":
        as_text = True
    await event.edit("`Calculating my internet speed. Please wait!`")
    start = datetime.now()
    s = speedtest.Speedtest()
    s.get_best_server()
    s.download()
    s.upload()
    end = datetime.now()
    ms = (end - start).microseconds / 1000
    response = s.results.dict()
    download_speed = response.get("download")
    upload_speed = response.get("upload")
    ping_time = response.get("ping")
    client_infos = response.get("client")
    i_s_p = client_infos.get("isp")
    i_s_p_rating = client_infos.get("isprating")
    reply_msg_id = event.message.id
    if event.reply_to_msg_id:
        reply_msg_id = event.reply_to_msg_id
    try:
        response = s.results.share()
        speedtest_image = response
        if as_text:
            await event.edit("""`SpeedTest completed in {} seconds`

`Download: {}`
`Upload: {}`
`Ping: {}`
`Internet Service Provider: {}`
`ISP Rating: {}`""".format(ms, convert_from_bytes(download_speed), convert_from_bytes(upload_speed), ping_time, i_s_p, i_s_p_rating))
        else:
            await borg.send_file(
                event.chat_id,
                speedtest_image,
                caption="**SpeedTest** completed in {} seconds".format(ms),
                force_document=as_document,
                reply_to=reply_msg_id,
                allow_cache=False
            )
            await event.delete()
    except Exception as exc:
        await event.edit("""**SpeedTest** completed in {} seconds
Download: {}
Upload: {}
Ping: {}

__With the Following ERRORs__
{}""".format(ms, convert_from_bytes(download_speed), convert_from_bytes(upload_speed), ping_time, str(exc))) 
开发者ID:Dark-Princ3,项目名称:X-tra-Telegram,代码行数:61,代码来源:speedtest.py


注:本文中的speedtest.Speedtest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。