-
Notifications
You must be signed in to change notification settings - Fork 0
/
speedtest.py
41 lines (31 loc) · 1.18 KB
/
speedtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# The SpeedTest package will give you information about your network speed
# Author: Florian Bouché
# Date: 2019-03-09
# Based on the package https://github.com/sivel/speedtest-cli
import utils
import os
import sys
import subprocess
import re
def run(string, entities):
"""The SpeedTest package will give you information about your network speed """
utils.output('inter', 'testing', utils.translate('testing'))
realpath = os.path.dirname(os.path.realpath(__file__))
process = subprocess.Popen(
[sys.executable, realpath + '/speedtest.lib.py', '--simple'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
(output, err) = process.communicate()
p_status = process.wait()
if err:
return utils.output('end', 'error', utils.translate('error'))
rawoutput = output.decode('utf-8')
data = {
'ping': re.search('Ping:(.+?)\n', rawoutput).group(1).strip(),
'download': re.search('Download:(.+?)\n', rawoutput).group(1).strip(),
'upload': re.search('Upload:(.+?)\n', rawoutput).group(1).strip()
}
return utils.output('end', 'done', utils.translate('done', data))