本文整理汇总了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)
示例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)
示例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)
示例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']
))
示例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}.")
)
示例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
示例7: __init__
# 需要导入模块: import speedtest [as 别名]
# 或者: from speedtest import Speedtest [as 别名]
def __init__(self):
self.name = _("Speedtest")
示例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()
示例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
示例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)))
示例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)))