當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。