Add support to write results to json file
This commit is contained in:
parent
7b09d8759f
commit
65a56097e5
|
@ -15,6 +15,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
@ -579,6 +580,8 @@ def speedtest():
|
||||||
parser.add_argument('--simple', action='store_true',
|
parser.add_argument('--simple', action='store_true',
|
||||||
help='Suppress verbose output, only show basic '
|
help='Suppress verbose output, only show basic '
|
||||||
'information')
|
'information')
|
||||||
|
parser.add_argument('--json',
|
||||||
|
help='Write results to specified JSON file')
|
||||||
parser.add_argument('--list', action='store_true',
|
parser.add_argument('--list', action='store_true',
|
||||||
help='Display a list of speedtest.net servers '
|
help='Display a list of speedtest.net servers '
|
||||||
'sorted by distance')
|
'sorted by distance')
|
||||||
|
@ -735,6 +738,13 @@ def speedtest():
|
||||||
print_('Upload: %0.2f M%s/s' %
|
print_('Upload: %0.2f M%s/s' %
|
||||||
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
((ulspeed / 1000 / 1000) * args.units[1], args.units[0]))
|
||||||
|
|
||||||
|
if args.json:
|
||||||
|
results = {"download": (dlspeed / 1000 / 1000) * args.units[1],
|
||||||
|
"upload": (ulspeed / 1000 / 1000) * args.units[1]}
|
||||||
|
with open(args.json, 'w') as jsonfile:
|
||||||
|
json.dump(results, jsonfile)
|
||||||
|
print_("Wrote results to JSON file: %s" % args.json)
|
||||||
|
|
||||||
if args.share and args.mini:
|
if args.share and args.mini:
|
||||||
print_('Cannot generate a speedtest.net share results image while '
|
print_('Cannot generate a speedtest.net share results image while '
|
||||||
'testing against a Speedtest Mini server')
|
'testing against a Speedtest Mini server')
|
||||||
|
|
Loading…
Reference in New Issue